I have a videoView where I show a video and I want to show the default media controllers. For some reason the controllers don't seem to want to show up.
I have tried creating the MediaController with xml, setting it to be always visible, attaching it to the media player with mMediaController.setMediaPlayer(mVideoView)
but nothing seems to work.
I am using the classic video player code from Google which can be found here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html
What can be happening ? Does the listener lose the event ? Is it not attached to the actual video playing ? Should I add something else to the code that I am using (see below) ?
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_content_video);
[...]
mVideoView = (VideoView) findViewById(R.id.surface);
mainVideoHolder = (LinearLayout) findViewById(R.id.main_video_holder);
holder = mVideoView.getHolder();
holder.addCallback(this);
mMediaController = new MediaController(this);
mMediaController.show();
}
private void playVideo() {
doCleanUp();
try {
mMediaPlayer = new MediaPlayer();
Log.d(tag, "surfaceCreated");
File f = new File(mAssetsPath);
File[] files = f.listFiles();
Log.d(tag, "File: " + files[0].toString());
URI uri = URI.create("file://" + (files[0].toString()));
File file = new File(uri);
ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
mMediaPlayer.setDataSource(parcel.getFileDescriptor());
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaController.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mMediaController);
} catch (Exception e) {
Log.e(tag, "error: " + e.getMessage(), e);
}
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(tag, "surfaceCreated called");
playVideo();
}
Any ideas would be greatly appreciated ?
There is no theme applied at the activity and the video plays normally without giving any error. It's just that the media controlos don't show up !
Thanks.
Where do you add your controller to a layout ? Also be sure the container is large enough. Give it a background and look if it displays well on screen before adding the video controller.