I want to play a video file while starting up an Android application. I've tried but it's not working properly. I've got an error message and it tells that the video can't be played. I've saved my video(.mp4 extension) in raw folder. I've set the path such as following:
path = "android.resource://com.easy.video/" + R.raw.myvideo;
This is my java file.
package com.easy.video;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Toast;
import android.widget.VideoView;
@SuppressWarnings("unused")
public class MainActivity extends Activity {
private VideoView videoView;
String extStorageDirectory;
protected static final int PLAY = 0x101;
protected static final int STOP = 0x102;
protected static final int PAUSE = 0x103;
int State;
private String current;
private String path;
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
path = "android.resource://com.easy.video/" + R.raw.myvideo;
mVideoView = (VideoView) findViewById(R.id.video);
if (path == null || path.length() == 0) {
Toast.makeText(MainActivity.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
mVideoView.setVideoPath(path);
mVideoView.start();
mVideoView.requestFocus();
}
mVideoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
Intent in = new Intent(MainActivity.this, NextActivity.class);
startActivity(in);
finish();
}
});
}
}
Actually I am not sure whether it is correct or not. I would be much grateful if anyone can be so kind enough to explain how to do this ?