1

I'm trying to play a video as a splash screen in my Android app. I've searched for a lot of tutorials and responser regarding problems with VideoView but I don't know what to do anymore...

I tried using hardcoded link to my sdcard (/sdcard/filename.mp4), I tried using Environment.getExternalStorageDirectory(), also I tried using a video from folder inside my app (R.raw.filename) and nothing seems to be working. I get either a black screen or a message that I can't play this video...

For every method I tried using various video formats (all of them supported by Android)

Here is my Java code:

package com.example.android;

import android.app.Activity;
import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

public class SplashScreen extends Activity implements OnClickListener {



protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_splash);

    String path = Environment.getExternalStorageDirectory() + "/splash.mp4";
    VideoView vid =(VideoView)findViewById(R.id.videoView1);
    vid.setVideoURI(Uri.parse(path));
    vid.setMediaController(new MediaController(this));
    vid.start();
    vid.requestFocus();
}





@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.pocetna, menu);
    return true;
}



/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_splash,
                container, false);
        return rootView;
    }

}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}






}

And my XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<VideoView
    android:id="@+id/videoView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</FrameLayout>
double-beep
  • 5,031
  • 17
  • 33
  • 41
user3503678
  • 51
  • 1
  • 4
  • Do you have permission to access external content in your manifest file http://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE ? – harism Jun 05 '14 at 22:03
  • I belive I don't (I will add one now and try), but video also failed playing when accessing it from R.raw (which is not external file if I am correct)? – user3503678 Jun 05 '14 at 22:08
  • UPDATE :Thank you very much, change in manifest file did it! You saved my life :D – user3503678 Jun 05 '14 at 22:13
  • Now I tried again implementing it with this: String path = "android:recources//" + getPackageName() +"/" +R.raw.splash; vid.setVideoURI(Uri.parse(path)); and I get a CANT PLAY error again :( – user3503678 Jun 05 '14 at 22:17

2 Answers2

3

Adding this in the manifest worked for me:

android.permission.READ_EXTERNAL_STORAGE
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Sharat
  • 81
  • 1
  • 2
0

I`m not sure but could It be possible that you need instead of vid.setVideoURI(Uri.parse(path)); vid.setVideoPath("/sdcard/splash.mp4");?

Or maybe you find there the answer: Playing a video in VideoView in Android

Community
  • 1
  • 1
weissja19
  • 535
  • 4
  • 11
  • I tried it that way also, but the problem obviously was in my manifest file (Thanks to @harism now that works). Now when I try to set a video from within my app (not on sd card) I get an error again. – user3503678 Jun 05 '14 at 22:19