问题
Can anyone in guide me how to play a video from a particular time? I have a video url ,i need to play the video from a particular time i used seekTo() but its not working. so i thought that first we need to stream the video to a file and then we need to play...but i dnt how to stream a video from a url.
Can anybody provide me the sample code.
Thanks.
回答1:
Hi try the following it will help you
<?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>
Android:
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
}
});
}
来源:https://stackoverflow.com/questions/8516657/how-to-stream-a-video-to-play-from-a-particular-time-in-android