0

I have spent many hours in trying to figure out why my VideoView wouldn't play any video. I have copied the working versions of the code from your website and others too. I have used MediaPlayer, VideoView, SurfaceView and SurfaceHolder and I can tell you the mistake is not in the code. The exception that I get is:

E/AndroidRuntime(953): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tcs.video/com.tcs.video.VideoPlayer}: java.lang.NullPointerException

Is it emulator related? Because: I also get 'Emulator without GPU emulation detected' Skipped 38 frames! The application may be doing too much work on its main thread.

The problem is not in the code, but simply something else that I fail to catch! Please help! The code is:

    public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
   // surfaceHolder.addCallback(this);
    surfaceHolder.setFixedSize(176, 144);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    MediaPlayer mediaPlayer = new MediaPlayer();

    String stringPath = "/raw/dryleaf.mp4";

    if (mediaPlayer.isPlaying()) {
        mediaPlayer.reset();
    }

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDisplay(surfaceHolder);

    try {
        mediaPlayer.setDataSource(stringPath);
        mediaPlayer.prepare();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mediaPlayer.start();
}
user2922935
  • 439
  • 4
  • 12
  • 1
    post a/ your complete stacktrace b/ the 4 ways you tried – njzk2 May 03 '14 at 16:34
  • possible duplicate of [Playing .MP4 video from raw resource folder](http://stackoverflow.com/questions/3944555/playing-mp4-video-from-raw-resource-folder) – njzk2 May 03 '14 at 16:34
  • Among any other possible problems, `/raw/dryleaf.mp4` does not exist on your device or emulator. – CommonsWare May 03 '14 at 16:39
  • thanks for the quick responses. I just discovered- 'Emulator without GPU emulation detected' Skipped 38 frames! The application may be doing too much work on its main thread. Also, the application NEVER halts at the debug breakpoints.. I think that's related too – user2922935 May 03 '14 at 16:43
  • @user2922935 if you're using the standard surface view you shouldn't have a problem playing in the emulator since that can fall back to a s/w implementation. I've seen problems trying to use a texture view in an emulator that doesn't support hardware gpu emulation, but I don't know if this is related. – dcow May 03 '14 at 17:51

1 Answers1

0

Thanks guys for entertaining my lame question. I broke my head on it!

@CommonsWare So I got rid of

    String stringPath = "/raw/dryleaf.mp4"; 

and the MediaPlayer object

@dcow Thanks for the helpful hint on the advantage of surface view.

Strangely, the *.mp4 file does not work at all ! That is why I am using *.3gp file type. The following code works!

    videoView = (VideoView)this.findViewById(R.id.videoView); 
    
    String uriPath = "android.resource://com.tcs.video/"+R.raw.vid_dryleaf;
    Uri uri = Uri.parse(uriPath);
    videoView.setVideoURI(uri); 
    videoView.requestFocus();
    videoView.start();

Please clarify the following questions:

  1. Why do we even need MediaPlayer object?

  2. What is the difference between MediaPlayer and MediaController ?

  3. Why didn't the mediaPlayer.setDataSource(StringPath) work?

  4. Inspite of using the exact same working code on a *.mp4 file in res folder taken from the parsed uriPath (and notice that MediaPlayer object was not used here), I got the Error "Unable to create media player" .. "Couldn't open file at client side, trying server side"

    If it helps, I am developing on windows 7.

Thanks

Community
  • 1
  • 1
user2922935
  • 439
  • 4
  • 12