tags:

views:

32

answers:

1

Why if I 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?

A: 

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

darbat
It works, thanks! By the way, you could add to your example the part that adds the listener.. ;)And, still, I have no samples folder in my android-sdk-linux\platforms\android-8\
Tom Brito
Edit: Added direct link to Api Demos.
darbat