Learn from this tutorial how to Play mp4 Movie using VideoView in Android Studio version 1.4. Create New Project with Application name “Play Video“; Minimum SDK – API 9: Android 2.3 (Gingerbread). Create New Directory in app -> res with name “raw“. Copy a video you want to display, in new created folder, raw; I used in this example a video with name “movie.mp4“. You can download it from here. In file activity_main.xml, create a VideoView to display your video.
<VideoView
    android:id="@+id/videoView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
In file activity_main.xml, create a transparent Button to play again video, on click.
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:background="@android:color/transparent" />
Complete code in MainActivity.java (in onCreate).
Button buttonPlayVideo2 = (Button)findViewById(R.id.button1);

getWindow().setFormat(PixelFormat.UNKNOWN);

//displays a video file
VideoView mVideoView2 = (VideoView)findViewById(R.id.videoView1);

String uriPath2 = "android.resource://com.example.toyo.playvideo/"+R.raw.movie;
Uri uri2 = Uri.parse(uriPath2);
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();

buttonPlayVideo2.setOnClickListener(new Button.OnClickListener() {
    @Override
    public void onClick(View v) {
        VideoView mVideoView2 = (VideoView) findViewById(R.id.videoView1);
        // VideoView mVideoView = new VideoView(this);
        String uriPath = "android.resource://com.example.toyo.playvideo/" + R.raw.movie;
        Uri uri2 = Uri.parse(uriPath);
        mVideoView2.setVideoURI(uri2);
        mVideoView2.requestFocus();
        mVideoView2.start();
    }
});
how to Play Video in Android Studio 1.4 Run the app in Emulator. Enjoy the result! Attention: the app is working only with Video with extension mp4. If you have an .avi movie or other extension, convert it on mp4 and add video to Android project. Watch the video tutorial to Play Video in Android Studio version 1.4: Download app PlayVideo.apk from here and install it on your device to play video. For further questions leave a message.

12 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

“Can’t Play this video” pop up comes

“Can’t Play this video” pop up comes. how to fix it?

    please connect internet then your video will play

This is how to fix “Can’t Play this video”;
In the MainActivity.java section, change the text “com.example.toyo.playvideo” to the name of your app.

still cant play

    Did you include your package name ?

thanks it works for me

How can I pause the video?

Its working.. Thank you..

cann’t play pop open
i have change the package name

I had the app crashing on videoView.requestFocus();
I found that the problem were two lines, missing above, and to be inserted in onCreate(…), above everything else :

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

As for the code above, indeed, I got the ““Can’t Play this video” pop up.

Changing it with the code from this site worked for me :
https://stackoverflow.com/questions/3263736/playing-a-video-in-videoview-in-android
(answer “Example Project”)

Leave a Reply to Lesson Learned Cancel reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*