1

I am trying to use Android's VideoView to play a video off of the sdcard folder on my device. It seems like it used to work just fine but I refactored some code and now I can't seem to get it working. Here is a sample:

// filepath = Environment.getExternalStorageDirectory().getPath() + "/test.mp4"
videoView = new VideoView(AkadiApplication.Instance().getApplicationContext());
videoView.setVideoURI(Uri.parse(filePath));
videoView.start();
videoView.requestFocus();

I have verified through the application that the file exists so I know it's not a FileNotFound issue.

Also, if I set a onComplete callback it is called as if the video played through (no video or sound, just a black square where the view should be). I know the video codec is valid because the device plays it outside my application. I think it might be related to a permission issue:

http://code.google.com/p/android/issues/detail?id=10197

dlee123
  • 81
  • 1
  • 4
  • what is this code inside of? Try changing your constructor to be `videoView = new VideoView(AkadiApplication.this);` Also how are you adding the videoView to the screen? with just the code you've posted I don't see how the VideoView would even get added to the screen. – FoamyGuy Jul 15 '12 at 23:47
  • Sorry, I should have explained what AkadiApplication is, it's a singleton of the application. It gives me access to the context wherever I am. This code is inside of a function that should return a View, in this case a VideoView that has been initialized and is playing. There is no layout file that has the VideoView, I am adding everything to the Activity programmatically. – dlee123 Jul 16 '12 at 13:55

1 Answers1

0

Create VideoView in your layout.xml file

 <VideoView android:id="@+id/video_view"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">
</VideoView>

And then in java file

VideoView mVideoView = (VideoView) findViewById(R.id.video_view); 
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
Nirali
  • 13,571
  • 6
  • 40
  • 53