samples/Support4Demos/src/main/java/com/example/android/supportv4/media/Playback.java
private void configMediaPlayerState() {
        Log.d(TAG, "configMediaPlayerState. mAudioFocus=" + mAudioFocus);
        if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
            // If we don't have audio focus and can't duck, we have to pause,
            if (mState == PlaybackState.STATE_PLAYING) {
                pause();
            }
        } else {  // we have audio focus:
            if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
                mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
            } else {
                if (mMediaPlayer != null) {
                    mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
                } // else do something for remote client.
            }
            // If we were playing when we lost focus, we need to resume playing.
            if (mPlayOnFocusGain) {
                if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                    Log.d(TAG,"configMediaPlayerState startMediaPlayer. seeking to "
                            + mCurrentPosition);
                    if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
                        mMediaPlayer.start();
                        mState = PlaybackState.STATE_PLAYING;
                    } else {
                        mMediaPlayer.seekTo(mCurrentPosition);
                        mState = PlaybackState.STATE_BUFFERING;
                    }
                }
                mPlayOnFocusGain = false;
            }
        }
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    }
/**
     * Reconfigures MediaPlayer according to audio focus settings and
     * starts/restarts it. This method starts/restarts the MediaPlayer
     * respecting the current audio focus state. So if we have focus, it will
     * play normally; if we don't have focus, it will either leave the
     * MediaPlayer paused or set it to a low volume, depending on what is
     * allowed by the current focus settings. This method assumes mPlayer !=
     * null, so if you are calling it, you have to do so from a context where
     * you are sure this is the case.
     */
Reconfigures MediaPlayer according to audio focus settings and
starts/restarts it. This method starts/restarts the MediaPlayer
respecting the current audio focus state. So if we have focus, it will
play normally; if we don't have focus, it will either leave the
MediaPlayer paused or set it to a low volume, depending on what is
allowed by the current focus settings. This method assumes mPlayer .
null, so if you are calling it, you have to do so from a context where
you are sure this is the case.
Reconfigures MediaPlayer according to audio focus settings and starts / restarts it . This method starts / restarts the MediaPlayer respecting the current audio focus state . So if we have focus it will play normally ; if we don ' t have focus it will either leave the MediaPlayer paused or set it to a low volume depending on what is allowed by the current focus settings . This method assumes mPlayer . null so if you are calling it you have to do so from a context where you are sure this is the case .
private void configMediaPlayerState() {
        Log.d(TAG, "configMediaPlayerState. mAudioFocus=" + mAudioFocus);
        if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
            if (mState == PlaybackState.STATE_PLAYING) {
                pause();
            }
        } else {  
            if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
                mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); 
            } else {
                if (mMediaPlayer != null) {
                    mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); 
                } 
            }
            if (mPlayOnFocusGain) {
                if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                    Log.d(TAG,"configMediaPlayerState startMediaPlayer. seeking to "
                            + mCurrentPosition);
                    if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
                        mMediaPlayer.start();
                        mState = PlaybackState.STATE_PLAYING;
                    } else {
                        mMediaPlayer.seekTo(mCurrentPosition);
                        mState = PlaybackState.STATE_BUFFERING;
                    }
                }
                mPlayOnFocusGain = false;
            }
        }
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    }
private void configMediaPlayerState ( ) { Log . d ( TAG , "configMediaPlayerState. mAudioFocus=" + mAudioFocus ) ; if ( mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK ) { if ( mState == PlaybackState . STATE_PLAYING ) { pause ( ) ; } } else { if ( mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK ) { mMediaPlayer . setVolume ( VOLUME_DUCK , VOLUME_DUCK ) ; } else { if ( mMediaPlayer != null ) { mMediaPlayer . setVolume ( VOLUME_NORMAL , VOLUME_NORMAL ) ; } } if ( mPlayOnFocusGain ) { if ( mMediaPlayer != null && ! mMediaPlayer . isPlaying ( ) ) { Log . d ( TAG , "configMediaPlayerState startMediaPlayer. seeking to " + mCurrentPosition ) ; if ( mCurrentPosition == mMediaPlayer . getCurrentPosition ( ) ) { mMediaPlayer . start ( ) ; mState = PlaybackState . STATE_PLAYING ; } else { mMediaPlayer . seekTo ( mCurrentPosition ) ; mState = PlaybackState . STATE_BUFFERING ; } } mPlayOnFocusGain = false ; } } if ( mCallback != null ) { mCallback . onPlaybackStatusChanged ( mState ) ; } }
Reconfigures MediaPlayer according to audio focus settings and
 starts/restarts it.
Reconfigures MediaPlayer according to audio focus settings and starts / restarts it .
// If we don't have audio focus and can't duck, we have to pause, // we have audio focus: // we'll be relatively quiet // we can be loud again // else do something for remote client. // If we were playing when we lost focus, we need to resume playing.