Jason
Jason

Reputation: 19

How to display mp4 video in videoview from raw folder

I am trying to display a mp4 video from a raw folder. The video is supposed to play in a videoview automatically when the app is open. I want the video to begin as soon as the activity is launched (This is the launcher activity). I also want the video to loop and have no sound. My xml is below.

<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linearLayout" />

This is the code I have.

String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";

VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);

mvideo.setVideoPath(Launcher);

MediaController controller = new MediaController(this);

mvideo.setMediaController(controller);

mvideo.requestFocus();

mvideo.start();

}

This code currently does not do anything but display a blank screen when I run the app and I don't know why. Can anyone help out?

Upvotes: 2

Views: 3612

Answers (2)

Jason
Jason

Reputation: 19

Thanks for the help guys, I figured it out.

VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
    Uri src = Uri.parse("android.resource://com.package/raw/video_name");
    videoView.setVideoURI(src);

    //videoView.setMediaController(new MediaController(this));

    videoView.start();

This worked for me.

Upvotes: -2

hakim
hakim

Reputation: 3909

I don't see you use this variable, and I don't see how you define Launcher variable.

String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";

to open video file from raw folder you can do this way:

Uri uri = Uri.parse(fileName);
mvideo.setVideoURI(uri);
mvideo.start()

I hope it can help solve your problem

Upvotes: 5

Related Questions