Example usage for android.media MediaPlayer setDisplay

List of usage examples for android.media MediaPlayer setDisplay

Introduction

In this page you can find the example usage for android.media MediaPlayer setDisplay.

Prototype

public void setDisplay(SurfaceHolder sh) 

Source Link

Document

Sets the SurfaceHolder to use for displaying the video portion of the media.

Usage

From source file:com.android.onemedia.playback.LocalRenderer.java

/**
 * Checks if the holder is ready and either sets up a callback to wait for
 * it or sets it directly. If//from  w  w  w  .ja va2s .  c  om
 *
 * @param holder
 * @param player
 * @return
 */
private boolean isHolderReady(final SurfaceHolder holder, final MediaPlayer player) {
    mHolder = holder;
    if (holder != null) {
        if (holder.getSurface() != null && holder.getSurface().isValid()) {
            player.setDisplay(holder);
            return true;
        } else {
            Log.w(TAG, "Holder not null, waiting for it to be ready");
            // If the holder isn't ready yet add a callback to set the
            // holder when it's ready.
            SurfaceHolder.Callback cb = new SurfaceHolder.Callback() {
                @Override
                public void surfaceDestroyed(SurfaceHolder arg0) {
                }

                @Override
                public void surfaceCreated(SurfaceHolder arg0) {
                    if (player.equals(mPlayer)) {
                        player.setDisplay(arg0);
                        preparePlayer(player, true);
                    }
                }

                @Override
                public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
                }
            };
            mHolderCB = cb;
            holder.addCallback(cb);
            return false;
        }
    }
    return true;
}