Mediacontroller Doesn't Work
My layout that contains videoView
Solution 1:
Try this :
publicstaticvoidplayVideo(String urlPath) {
VideoView mVideoview; // Added this line
mVideoView =(VideoView) findViewByid(R.yourvideoviewid);
try {
// Start the MediaControllerMediaController mediacontroller = newMediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURLUri mVideo = Uri.parse(urlPath);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
mVideoview.requestFocus();
mVideoview.setOnPreparedListener(newOnPreparedListener() {
// Close the progress bar and play the videopublicvoidonPrepared(MediaPlayer mp) {
mVideoview.start();
}
});
mVideoview.setOnCompletionListener(newOnCompletionListener() {
publicvoidonCompletion(MediaPlayer mp) {
}
});
}
Solution 2:
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java
// Get VideoView in layout xmlVideoViewmVideoView= (VideoView) findViewById(R.id.videoView);
// MediaController provide controller, contains the buttons// like "Play/Pause", "Rewind", "Fast Forward" and a progress slideMediaControllermediaController=newMediaController(this);
mediaController.setAnchorView(mVideoView);
mVideoView.setMediaController(mediaController);
mVideoView.setVideoPath("/path/to/your/videofile");
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(newOnPreparedListener() {
publicvoidonPrepared(MediaPlayer mp) {
mVideoView.start();
}
});
Solution 3:
Add frame layout for anchor view in your xml
<FrameLayout android:id="@+id/controllerAnchor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
/>
and set this to your media controller
mediacontroller.setAnchorView(findViewById(R.id.controllerAnchor);
Post a Comment for "Mediacontroller Doesn't Work"