我使用下面的代码在模拟器和设备上进行测试,结果出来了,模拟器可以在VideoView下面显示MediaController(默认位于屏幕的底部)。但是,当我在设备中测试时,它没有向我显示MediaController。 我想知道原因。
final VideoView videoView = (VideoView)findViewById(R.id.videoGuide1);
videoView.setOnPreparedListener(new OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer mp){
mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener(){
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height){
MediaController mediaController = new MediaController(WatchVideo.this);;
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);
}
});
}
});
答案 0 :(得分:1)
试试这个对我有用....
VideoView vv;
vv = (VideoView) findViewById(R.id.videoView);
vv.setVideoPath(filename);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
}
}
答案 1 :(得分:0)
尝试这种方式
MediaController controller;
Videoview videoview;
videoview=(VideoView)findViewById(R.id.videoview);
controller = new MediaController(this);
videoview.setVideoURI(Uri.parse(path));
videoview.setMediaController(controller);
controller.setMediaPlayer(videoview);
videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
int duration = videoview.getDuration();
videoview.requestFocus();
videoview.start();
controller.show();
Log.d("Video view is prepared","------>");
}
});