I want to play a video file from raw folder as splash.But it is not working.Can anyone please help me to sort out this problem.
This is my code
public class SplashActivity extends Activity implements OnCompletionListener{
private MediaController mc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
VideoView vd = (VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.sea);
//mc = new MediaController(this);
//vd.setMediaController(mc);
vd.requestFocus();
vd.setVideoURI(uri);
vd.start();
// vd.setOnCompletionListener(this);
}
public void onCompletion(MediaPlayer mp) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
And my layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView">
</VideoView>
< /LinearLayout>
public class SplashActivity extends Activity{
private String mSplashVideoPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mSplashVideoPath = Environment.getExternalStorageDirectory() + PATH;
copyVideoFile();
final VideoView mVideoView = (VideoView) findViewById(R.id.videoView);
mVideoView.requestFocus();
mVideoView.setVideoPath(mSplashVideoPath);
mVideoView.start();
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
});
}
private void copyVideoFile() {
final File videoPath = new File(mSplashVideoPath);
if (!videoPath.exists()) {
videoPath.mkdirs();
}
final File videoFile = new File(mSplashVideoPath);
if (!videoFile.exists()) {
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(ASSETS_SPLASH_VIDEO);
out = new FileOutputStream(videoFile);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
e.printStackTrace();
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
}