如何在Android中从特定时间播放视频?

时间:2011-12-15 07:42:31

标签: android video-streaming

有人可以指导我如何播放特定时间的视频吗? 我有一个视频网址,我需要播放特定时间的视频,我使用的是seekTo(),但它不起作用。所以我认为首先我们需要将视频流式传输到文件,然后我们需要播放...但我知道如何从网址流式传输视频。

任何人都可以提供示例代码。

感谢。

1 个答案:

答案 0 :(得分:2)

嗨试试以下它会帮助你

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
     <VideoView android:id="@+id/playvideo" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:keepScreenOn="true" 
        android:layout_centerInParent="true"></VideoView> 



</RelativeLayout>

机器人:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.videolayout);
        this.videoView=(VideoView)findViewById(R.id.playvideo);


         play();

    }
     private void play(){
            MediaController mediaController = new MediaController(this);
            mediaController.setAnchorView(this.videoView);  

         Uri video=Uri.parse("http://your.mp4/35.mp4");
            Log.e("Uri video",video.toString());
            videoView.setMediaController(mediaController);
            videoView.setVideoURI(video);     
            videoView.seekTo(60000*10);//10 mins...
            videoView.start();
            videoView.setOnCompletionListener(new OnCompletionListener(){

                public void onCompletion(MediaPlayer arg0) {
                    // TODO Auto-generated method stub

                }

            });
     }