Android: Displaying Video on VideoView
- by AndroidDev93
I'm trying to display a video in my sdcard on the video view. Here is my code:
String name = Environment.getExternalStorageDirectory() + "/test.mp4";
final VideoView videoView = (VideoView)findViewById(R.id.videoView1);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
videoView.start();
}
});
videoView.setVideoPath(name);
The file I am trying to open is called test.mp4 and its located within the sdcard folder. I get an error saying the application has unfortunately stopped. I would appreciate it if someone could help me. Thanks.
EDIT :
I used the debugger and found out that I get an InvocationTargetException.
The detailed message says that :
Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=file:///mnt/sdcard/test.mp4 }} to activity : java.lang.NullPointerException
EDIT :
I looked at the logcat again and it seems to give the error at
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
I'm guessing either videoView or MediaPlayer is null.