How to start MPlayer from onCreate?
Why if I 开发者_JS百科start the MPlayer from the onCreate it doesn't start? I tried also from onStart(), but the only working way was from onTouch or on key press.
Any idea how to start it without any additional user input needed?
You should start player after surface is created. If you want to start playback at start of the Activity, you should do it on surfaceCreated event. You can listen to this event by implementing SurfaceHolder.Callback
public void onCreate(Bundle icicle) {
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo();
}
Try to follow Android ApiDemos. Video Player example can be found at:
...android-sdk-windows\platforms\android-x\samples\ApiDemos\src\com\example\android\apis\media\MediaPlayerDemo_Video.java
or web link: ApiDemos Media
精彩评论