我写了一个非常简单的视频播放器,这是代码:
VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("http://192.168.1.20/test/v_2.flv");
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
布局:
<VideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="161dp" />
它播放视频,但我该如何添加这些功能呢?
1-播放器在下载视频时加载
2-当我点击它时,它会播放,停止并向后移动或向前移动。
我该怎么办?
答案 0 :(得分:1)
试试这个:
VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("http://192.168.1.20/test/v_2.flv");
//SHOW THE PROGRESS DIALOG(LOADING...)
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
try{
videoView.setMediaController(mediaController); //ADD MEDIA CONTROLS(PLAY, STOP, FORWARD etc.)
videoView.setVideoURI(uri);
} catch (Exception e) {
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
progressDialog.dismiss();
videoView.start();
}
});