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.
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();
}
});
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.
Watchthe video tutorial to Play Video in Android Studio version 1.4:Download appPlayVideo.apk from here and install it on your device to play video.
For furtherquestionsleave a message.
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 :
“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”)