samples/Support4Demos/src/main/java/com/example/android/supportv4/media/Playback.java
private void createMediaPlayerIfNeeded() {
        Log.d(TAG, "createMediaPlayerIfNeeded. needed? " + (mMediaPlayer==null));
        if (mMediaPlayer == null) {
            mMediaPlayer = new MediaPlayer();

            // Make sure the media player will acquire a wake-lock while
            // playing. If we don't do that, the CPU might go to sleep while the
            // song is playing, causing playback to stop.
            mMediaPlayer.setWakeMode(mService.getApplicationContext(),
                    PowerManager.PARTIAL_WAKE_LOCK);

            // we want the media player to notify us when it's ready preparing,
            // and when it's done playing:
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnErrorListener(this);
            mMediaPlayer.setOnSeekCompleteListener(this);
        } else {
            mMediaPlayer.reset();
        }
    }
/**
     * Makes sure the media player exists and has been reset. This will create
     * the media player if needed, or reset the existing media player if one
     * already exists.
     */
Makes sure the media player exists and has been reset. This will create
the media player if needed, or reset the existing media player if one
already exists.
Makes sure the media player exists and has been reset . This will create the media player if needed or reset the existing media player if one already exists .
private void createMediaPlayerIfNeeded() {
        Log.d(TAG, "createMediaPlayerIfNeeded. needed? " + (mMediaPlayer==null));
        if (mMediaPlayer == null) {
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setWakeMode(mService.getApplicationContext(),
                    PowerManager.PARTIAL_WAKE_LOCK);
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnErrorListener(this);
            mMediaPlayer.setOnSeekCompleteListener(this);
        } else {
            mMediaPlayer.reset();
        }
    }
private void createMediaPlayerIfNeeded ( ) { Log . d ( TAG , "createMediaPlayerIfNeeded. needed? " + ( mMediaPlayer == null ) ) ; if ( mMediaPlayer == null ) { mMediaPlayer = new MediaPlayer ( ) ; mMediaPlayer . setWakeMode ( mService . getApplicationContext ( ) , PowerManager . PARTIAL_WAKE_LOCK ) ; mMediaPlayer . setOnPreparedListener ( this ) ; mMediaPlayer . setOnCompletionListener ( this ) ; mMediaPlayer . setOnErrorListener ( this ) ; mMediaPlayer . setOnSeekCompleteListener ( this ) ; } else { mMediaPlayer . reset ( ) ; } }
Makes sure the media player exists and has been reset.
Makes sure the media player exists and has been reset .
// Make sure the media player will acquire a wake-lock while // playing. If we don't do that, the CPU might go to sleep while the // song is playing, causing playback to stop. // we want the media player to notify us when it's ready preparing, // and when it's done playing: