2

So I'm trying to play a basic avi video in android, it seems to run fine on Windows Media Player, VLC, etc. so it doesn't look like it's requiring any complicated codecs. I have a video view in my app and that's it, and I have my video in my resources directory under:

res/raw/my_video.avi

This is the code I'm using to load my video:

setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.start();

And it does not work. I get a popup saying "Can't play this video" along with a logcat message:

03-10 01:42:12.102: E/(185): Failed to open file 'android.resource://com.securespaces.android.bootstrap/2130968576'. (No such file or directory)
03-10 01:42:12.102: E/MediaPlayer(9737): error (1, -2147483648)
03-10 01:42:12.142: E/MediaPlayer(9737): Error (1,-2147483648)

I'm running this on a Nexus 5 running 4.4.2 stock by the way. I'm following instructions that I found in other stack over flow questions here: How to play videos in android from assets folder or raw folder? with some minor tweaks so that I am using a VideoView that I grab from a layout file.

I'm really stumped as to why this isn't working. I've browsed through a few questions on this subject, but this feels like something that should be a duplicate. I'm running this on a Nexus 5 running 4.4.2 stock by the way.

To clarify the question, I'm wondering what I am doing wrong, or is there an alternative for just playing a simple AVI video?

Community
  • 1
  • 1
Andrew T.
  • 4,598
  • 4
  • 35
  • 54
  • Try out like `Uri video = Uri.parse("android.resource://com.securespaces.android.bootstrap/" + R.raw.my_video);` – GrIsHu Mar 10 '14 at 06:18

2 Answers2

1

Write your package name statically and check whether video plays or not.

Try out as below:

VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://com.securespaces.android.bootstrap/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

Implement this :

public static void getVideoFromRaw(String rawPath) {

try {
    // Start the MediaController
    MediaController mediacontroller = new MediaController(mContext);
    mediacontroller.setAnchorView(mVideoview);
    // Get the URL from String VideoURL
    Uri mVideo = Uri.parse(rawPath);
    mVideoview.setMediaController(mediacontroller);
    mVideoview.setVideoURI(mVideo);

} catch (Exception e) {
    Log.e("Error", e.getMessage());
    e.printStackTrace();

}

mVideoview.requestFocus();
mVideoview.setOnPreparedListener(new OnPreparedListener() {
    // Close the progress bar and play the video
    public void onPrepared(MediaPlayer mp) {
        mVideoview.start();

    }
});

mVideoview.setOnCompletionListener(new OnCompletionListener() {

    public void onCompletion(MediaPlayer mp) {

    }
});

}

Thanks

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69