Issue
I'm trying to display an mp4 video from the app resources inside a VideoView, referring to this answer and this tutorial I used the following way:
// make the videoView visible
storyVideo.setVisibility(View.VISIBLE);
// set Video Preferences
storyVideo.requestFocus();
storyVideo.setBackgroundColor(Color.BLACK);
// get & set the video URI
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.story_media4);
storyVideo.setVideoURI(uri);
// Start The Video
storyVideo.start();
where story_media4 is stored in the raw file in resources:
Solution
Actually the video was displaying but not showing, with the help of this answer, I could display the video after setting video_view.setZOrderOnTop(true); on both video URI setting and video prepared listener method:
// set Video Preferences
storyVideo.requestFocus();
storyVideo.setZOrderOnTop(true);
// get & set the video URI
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.story_media4);
storyVideo.setVideoURI(uri);
// when the video is ready for display
storyVideo.setOnPreparedListener(onVideoPrepared);
private MediaPlayer.OnPreparedListener onVideoPrepared = new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
storyVideo.setZOrderOnTop(true);
// to start the video
storyVideo.start();
}
};
Update: For the above method, the video is going on Top of all of the views, if -for a reason- you want the video to be covered by one or more views (like sticker or description text) the best way is to set the background of the video to TRANSPARENT :
storyVideo.setBackgroundColor(Color.TRANSPARENT);
Answered By - Muhammed Refaat

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.