Scenario:
1) Start MediaPlayer instance in a background service and make it play
a video (MP4) file. At this point, setDisplay() has not been called,
so as per the documentation, only the audio track is being played at
this point.
2) At some later point in time, an activity containing a SurfaceView
in its layout starts, binds to the service, obtains a reference to the
embedded MediaPlayer and calls setDisplay() on it with the view's
holder (inside the surfaceCreated() callback). This causes the video
to start being displayed, which is the desired behavior.
3) When the activity stops (becomes non-visible), it tries to make the
MediaPlayer instance go back to audio-only mode by calling
setDisplay(null). From this point onwards, error messages like "03-28
22:55:43.525: ERROR/Overlay(1217): overlay_queueBuffer:
MSMFB_OVERLAY_PLAY error!
" start appearing in the logs.
4) When the activity becomes visible again later, this time when it
calls setDisplay() with a new SurfaceHolder (inside surfaceCreated()),
nothing seems to happen. The video does not start being displayed (as
it did in step 2). Meanwhile, the error message in step 3 keeps
appearing recurrently in the logs.

Is this something I'm doing wrong? Can I not call setDisplay(null) to
unset the display after it's already been set? The documentation isn't
too clear about this; it only says that setDisplay() can be called at
any time in the player's lifecycle. It does not mention whether it can
be called multiple times on the same player instance with toggled
values alternating each other (once with a valid SurfaceHolder, the
next time with null, and so on).

Even looking at the MediaPlayer source:
public void setDisplay(SurfaceHolder sh) {
563         mSurfaceHolder = sh;
564         if (sh != null) {
565             mSurface = sh.getSurface();
566         } else {
567             mSurface = null;
568         }
569         _setVideoSurface();
570         updateSurfaceScreenOn();
571     }

The code doesn't give any indication that setDisplay() cannot be
called multiple times, or that it cannot be called with null after a
display has already been set.

Any pointers would be appreciated.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to