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();
}