user3503678
user3503678

Reputation: 51

Can't play this video because of VideoView error

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>

Upvotes: 1

Views: 6926

Answers (2)

Sharat
Sharat

Reputation: 81

Adding this in the manifest worked for me:

android.permission.READ_EXTERNAL_STORAGE

Upvotes: 3

weissja19
weissja19

Reputation: 545

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

Upvotes: 0

Related Questions