VideoViewを使用してビデオを再生するAndroidアプリケーションがあり、メディアコントローラーも使用しています。
私の問題は、ビデオの再生中にメディアコントローラーが消えるのを防ぐことができないことです。また、ユーザーがメディアコントローラーを使用して最初にビデオを開始できるように、ビデオが開始する前にメディアコントローラーを表示したいと思います。MediaController.show(0)を使用してみましたが、問題は解決しませんでした。これが私のコードです:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);
MediaController mc = new MediaController(this);
mVideoView.setMediaController(mc);
mPlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
playVideo();
}
});
mPause.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.pause();
}
}
});
mReset.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.seekTo(0);
}
}
});
mStop.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
current = null;
mVideoView.stopPlayback();
}
}
});
}
private void playVideo() {
try {
final String path = "http://toop.voxelperfect.net/video6.mp4";
System.out.println("path "+path);
Log.v(TAG, "path: " + path);
if (path == null || path.length() == 0) {
Toast.makeText(SampleActivity.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
} else {
System.out.println("else ");
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
System.out.println("mVideoView.start() ");
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
current = path;
MediaController mc = new MediaController(this);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(Uri.parse(path));
mVideoView.start();
mVideoView.requestFocus();
mc.show(0);
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage());
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}