有谁可以指导我如何播放某个特定时间的视频吗?我有一个视频网址,我需要播放的视频从我使用seekTo()的特定时间,但它不工作。所以我想,首先我们需要将视频流式传输到一个文件中,然后我们需要play...but,我不知道如何从url流式传输视频。
有没有人能给我提供示例代码。
谢谢。
发布于 2011-12-21 00:33:24
嗨,试试下面的吧,它会帮到你的
<?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
复制相似问题