Android: Displaying Video on VideoView

Posted by AndroidDev93 on Stack Overflow See other posts from Stack Overflow or by AndroidDev93
Published on 2012-06-11T18:50:16Z Indexed on 2012/06/11 22:40 UTC
Read the original article Hit count: 324

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about videoview