android.media.AudioManager#AUDIOFOCUS_LOSS源码实例Demo

下面列出了android.media.AudioManager#AUDIOFOCUS_LOSS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyBookshelf   文件: ReadAloudService.java
@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            // 重新获得焦点,  可做恢复播放,恢复后台音量的操作
            if (!pause) {
                resumeReadAloud();
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            // 永久丢失焦点除非重新主动获取,这种情况是被其他播放器抢去了焦点,  为避免与其他播放器混音,可将音乐暂停
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            // 暂时丢失焦点,这种情况是被其他应用申请了短暂的焦点,可压低后台音量
            if (!pause) {
                pauseReadAloud(false);
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音),
            break;
    }
}
 
public void onFocusChange(int state) {
    Log.d("FMediaPlayer", "Focus change current state is " + state);
    switch (state) {
        case AudioManager.AUDIOFOCUS_GAIN:
            Log.d("FMediaPlayer", "Focus change then start again");
            fMediaPlayer.audioFocusGain();
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            Log.d("FMediaPlayer", "Focus change then pause isPlaying:" + fMediaPlayer.isPlaying());
            fMediaPlayer.audioFocusLoss(fMediaPlayer.isPlaying());
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            Log.d("FMediaPlayer", "Focus change then pause isPlaying:" + fMediaPlayer.isPlaying());
            fMediaPlayer.audioFocusLoss(fMediaPlayer.isPlaying());
    }
}
 
@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        abandonAudioFocus();
        mPlayOnAudioFocus = false;
        emitter.onStop();
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
        if (MusicControlModule.INSTANCE.isPlaying()) {
            mPlayOnAudioFocus = true;
            emitter.onPause();
        }
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        volume.setCurrentVolume(40);
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        if (volume.getCurrentVolume() != 100) {
            volume.setCurrentVolume(100);
        }
        if (mPlayOnAudioFocus) {
            emitter.onPlay();
        }
        mPlayOnAudioFocus = false;
    }
}
 
源代码4 项目: Fatigue-Detection   文件: AudioFocusRequest.java
public void onAudioFocusChange(int focusChange) {
    if(focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        Log.d(TAG, "audio focus loss");
        mAudioManager.abandonAudioFocus(this);
    }
    audioFocusRequest.fireFocusChange();
}
 
源代码5 项目: Dashchan   文件: VideoUnit.java
@Override
public void onAudioFocusChange(int focusChange) {
	if (!initialized) {
		return;
	}
	switch (focusChange) {
		case AudioManager.AUDIOFOCUS_LOSS: {
			setPlaying(false, false);
			updatePlayState();
			break;
		}
		case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: {
			boolean playing = player.isPlaying();
			setPlaying(false, false);
			if (playing) {
				pausedByTransientLossOfFocus = true;
			}
			updatePlayState();
			break;
		}
		case AudioManager.AUDIOFOCUS_GAIN: {
			if (pausedByTransientLossOfFocus) {
				setPlaying(true, false);
			}
			updatePlayState();
			break;
		}
	}
}
 
源代码6 项目: android-music-player   文件: PlaybackManager.java
/**
 * Called by AudioManager on audio focus changes.
 * Implementation of {@link AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackState.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackState.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackState.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
源代码7 项目: coursera-android   文件: AudioRecordingActivity.java
@Override
public void onAudioFocusChange(int focusChange) {

    if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        mAudioManager.abandonAudioFocus(afChangeListener);

        // Stop playback, if necessary
        if (null != mPlayer && mPlayer.isPlaying())
            stopPlaying();
    }

}
 
/**
 * Called by AudioManager on audio focus changes.
 * Implementation of {@link AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        // We have gained focus:
        mAudioFocus = AUDIO_FOCUSED;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
        mAudioFocus = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK;

        // If we are playing, we need to reset media player by calling configMediaPlayerState
        // with mAudioFocus properly set.
        if (mState == PlaybackStateCompat.STATE_PLAYING && !canDuck) {
            // If we don't have audio focus and can't duck, we save the information that
            // we were playing, so that we can resume playback once we get the focus back.
            mPlayOnFocusGain = true;
        }
    } else {
        Log.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: "+ focusChange);
    }
    configMediaPlayerState();
}
 
源代码9 项目: TigerVideo   文件: VideoPlayerView.java
/************************ 音频焦点获取与释放 ********************************/

    @Override
    public void onAudioFocusChange(int focusChange) {

        switch (focusChange) {
            case AudioManager.AUDIOFOCUS_GAIN:
                if(PlayerManager.getInstance().getState() == PlayState.STATE_PAUSE) {
                    PlayerManager.getInstance().play();
                }
                break;
            case AudioManager.AUDIOFOCUS_LOSS:
                //长时间失去Focus
                PlayerManager.getInstance().stop();
                Utils.log("AudioManager.AUDIOFOCUS_LOSS");
                break;
            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                //短时间失去Focus
                if (PlayerManager.getInstance().isPlaying()) {
                    PlayerManager.getInstance().pause();
                }
                Utils.log("AudioManager.AUDIOFOCUS_LOSS_TRANSIENT");
                break;
            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                break;
        }
    }
 
源代码10 项目: android_9.0.0_r45   文件: FocusRequester.java
/**
 * Handle the loss of focus resulting from a given focus gain.
 * @param focusGain the focus gain from which the loss of focus is resulting
 * @param frWinner the new focus owner
 * @return true if the focus loss is definitive, false otherwise.
 */
@GuardedBy("MediaFocusControl.mAudioFocusLock")
boolean handleFocusLossFromGain(int focusGain, final FocusRequester frWinner, boolean forceDuck)
{
    final int focusLoss = focusLossForGainRequest(focusGain);
    handleFocusLoss(focusLoss, frWinner, forceDuck);
    return (focusLoss == AudioManager.AUDIOFOCUS_LOSS);
}
 
源代码11 项目: Saiy-PS   文件: VolumeHelper.java
@Override
public void onAudioFocusChange(final int focusChange) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "AudioManager focusChange: " + focusChange);
    }

    switch (focusChange) {

        case AudioManager.AUDIOFOCUS_GAIN:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "AudioManager focusChange: AUDIOFOCUS_GAIN");
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "AudioManager focusChange: AUDIOFOCUS_LOSS");
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "AudioManager focusChange: AUDIOFOCUS_LOSS_TRANSIENT");
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "AudioManager focusChange: AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
            }
            break;
        default:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "AudioManager focusChange: AUDIOFOCUS default");
            }
            break;
    }
}
 
源代码12 项目: Jockey   文件: MusicPlayer.java
@Override
public void onAudioFocusChange(int focusChange) {
    Timber.i("AudioFocus changed (%d)", focusChange);

    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS:
            Timber.i("Focus lost. Pausing music.");
            mFocused = false;
            mResumeOnFocusGain = false;
            pause();
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            Timber.i("Focus lost transiently. Pausing music.");
            boolean resume = isPlaying() || mResumeOnFocusGain;
            mFocused = false;
            pause();
            mResumeOnFocusGain = resume;
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                Timber.i("Focus lost transiently. Letting system duck.");
            } else {
                Timber.i("Focus lost transiently. Ducking.");
                mMediaPlayer.setVolume(DUCK_VOLUME);
            }
            break;
        case AudioManager.AUDIOFOCUS_GAIN:
            Timber.i("Regained AudioFocus");
            mMediaPlayer.setVolume(1f);
            if (mResumeOnFocusGain) play();
            mResumeOnFocusGain = false;
            break;
        default:
            Timber.i("Ignoring AudioFocus state change");
            break;
    }
    updateNowPlaying();
    updateUi();
}
 
public void onAudioFocusChange(int focusChange) {
    if (mPlayer != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            switch (focusChange) {
                case AudioManager.AUDIOFOCUS_GAIN:
                    if (playbackDelayed || !userPaused) {
                        synchronized(focusLock) {
                            playbackDelayed = false;
                        }
                        boolean autostart = mPlayer.getConfig().getAutostart();
                        if (autostart) {
                            mPlayer.play();
                        }
                    }
                    break;
                case AudioManager.AUDIOFOCUS_LOSS:
                    synchronized(focusLock) {
                        wasInterrupted = true;
                        playbackDelayed = false;
                    }
                    mPlayer.pause();
                    hasAudioFocus = false;
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                    synchronized(focusLock) {
                        wasInterrupted = true;
                        playbackDelayed = false;
                    }
                    mPlayer.pause();
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                    // ... pausing or ducking depends on your app
                    break;
            }
        } else {
            lowerApiOnAudioFocus(focusChange);
        }
    }
}
 
源代码14 项目: coursera-android   文件: AudioRecordingActivity.java
@Override
public void onAudioFocusChange(int focusChange) {

	if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
		mAudioManager.abandonAudioFocus(afChangeListener);

		// Stop playback, if necessary
		if (null != mPlayer && mPlayer.isPlaying())
			stopPlaying();
	}

}
 
源代码15 项目: CodenameOne   文件: BackgroundAudioService.java
@Override
public void onAudioFocusChange(int focusChange) {
    switch( focusChange ) {
        case AudioManager.AUDIOFOCUS_LOSS: {
            if( RemoteControlCallback.isPlaying() ) {
                RemoteControlCallback.stop();
                initMediaSessionMetadata();
                showPausedNotification();
            }
            break;
        }
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: {
            RemoteControlCallback.pause();
            initMediaSessionMetadata();
            showPausedNotification();
            break;
        }
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
            if( RemoteControlCallback.isPlaying() ) {
                RemoteControlCallback.setVolume(0.3f, 0.3f);
            }
            break;
        }
        case AudioManager.AUDIOFOCUS_GAIN: {
            
            if( !RemoteControlCallback.isPlaying() ) {
                RemoteControlCallback.play();
                initMediaSessionMetadata();
                showPlayingNotification();
            }
            RemoteControlCallback.setVolume(1.0f, 1.0f);
            
            break;
        }
    }
}
 
@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            if (mPlayOnAudioFocus && !isPlaying()) {
                play();
            } else if (isPlaying()) {
                setVolume(MEDIA_VOLUME_DEFAULT);
            }
            mPlayOnAudioFocus = false;
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            setVolume(MEDIA_VOLUME_DUCK);
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            if (isPlaying()) {
                mPlayOnAudioFocus = true;
                pause();
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            mAudioManager.abandonAudioFocus(this);
            mPlayOnAudioFocus = false;
            stop();
            break;
    }
}
 
源代码17 项目: Telegram-FOSS   文件: AudioFocusManager.java
@Override
public void onAudioFocusChange(int focusChange) {
  // Convert the platform focus change to internal state.
  switch (focusChange) {
    case AudioManager.AUDIOFOCUS_LOSS:
      audioFocusState = AUDIO_FOCUS_STATE_LOST_FOCUS;
      break;
    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
      audioFocusState = AUDIO_FOCUS_STATE_LOSS_TRANSIENT;
      break;
    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
      if (willPauseWhenDucked()) {
        audioFocusState = AUDIO_FOCUS_STATE_LOSS_TRANSIENT;
      } else {
        audioFocusState = AUDIO_FOCUS_STATE_LOSS_TRANSIENT_DUCK;
      }
      break;
    case AudioManager.AUDIOFOCUS_GAIN:
      audioFocusState = AUDIO_FOCUS_STATE_HAVE_FOCUS;
      break;
    default:
      Log.w(TAG, "Unknown focus change type: " + focusChange);
      // Early return.
      return;
  }

  // Handle the internal state (change).
  switch (audioFocusState) {
    case AUDIO_FOCUS_STATE_NO_FOCUS:
      // Focus was not requested; nothing to do.
      break;
    case AUDIO_FOCUS_STATE_LOST_FOCUS:
      playerControl.executePlayerCommand(PLAYER_COMMAND_DO_NOT_PLAY);
      abandonAudioFocus(/* forceAbandon= */ true);
      break;
    case AUDIO_FOCUS_STATE_LOSS_TRANSIENT:
      playerControl.executePlayerCommand(PLAYER_COMMAND_WAIT_FOR_CALLBACK);
      break;
    case AUDIO_FOCUS_STATE_LOSS_TRANSIENT_DUCK:
      // Volume will be adjusted by the code below.
      break;
    case AUDIO_FOCUS_STATE_HAVE_FOCUS:
      playerControl.executePlayerCommand(PLAYER_COMMAND_PLAY_WHEN_READY);
      break;
    default:
      throw new IllegalStateException("Unknown audio focus state: " + audioFocusState);
  }

  float volumeMultiplier =
      (audioFocusState == AUDIO_FOCUS_STATE_LOSS_TRANSIENT_DUCK)
          ? AudioFocusManager.VOLUME_MULTIPLIER_DUCK
          : AudioFocusManager.VOLUME_MULTIPLIER_DEFAULT;
  if (AudioFocusManager.this.volumeMultiplier != volumeMultiplier) {
    AudioFocusManager.this.volumeMultiplier = volumeMultiplier;
    playerControl.setVolumeMultiplier(volumeMultiplier);
  }
}
 
public void onAudioFocusChange(int focusChange) {
    boolean isPause = mModeService.getMode(focusChange);
    LogUtil.d(TAG, "isPause = " + isPause);
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS:
            mAM.unregisterMediaButtonEventReceiver(mMediaButtonReceiverComponent);

            setMediaAudioFocusStatus(false);

            informMusicPause();
            LogUtil.d(TAG, "music AUDIOFOCUS_LOSS");
            MsgHandlerCenter.dispatchMessage(CommonParams.MSG_CMD_AUDIO_FOCUS_LOSS);
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            mAM.unregisterMediaButtonEventReceiver(mMediaButtonReceiverComponent);

            setMediaAudioFocusStatus(false);

            if (isPause) {
                informMusicPause();
            }
            LogUtil.d(TAG, "music AUDIOFOCUS_LOSS_TRANSIENT");
            MsgHandlerCenter.dispatchMessage(CommonParams.MSG_CMD_AUDIO_FOCUS_LOSS_TRANSIENT);
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // setMediaAudioFocusStatus(false);

            LogUtil.d(TAG, "music AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
            MsgHandlerCenter.dispatchMessage(CommonParams.MSG_CMD_AUDIO_FOCUS_LOSS_TRANSIENT_CAN_DUCK);
            break;
        case AudioManager.AUDIOFOCUS_GAIN:
            mAM.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

            setMediaAudioFocusStatus(true);
            // For HU from YF, it is possible to get audio focus in failure when resume playing
            // Try to resume playing when audio focus regain
            if (!isPause || getAudioFocusFailedWhenResume) {
                informMusicResume();
                getAudioFocusFailedWhenResume = false;
            }
            LogUtil.d(TAG, "music AUDIOFOCUS_GAIN");
            MsgHandlerCenter.dispatchMessage(CommonParams.MSG_CMD_AUDIO_FOCUS_GAIN);
            break;

        default:
            break;
    }
}
 
源代码19 项目: Bop   文件: ServicePlayMusic.java
/**
 * Does something when the audio focus state changed
 *
 * @note Meaning it runs when we get and when we don't get
 * the audio focus from `#requestAudioFocus()`.
 * <p>
 * For example, when we receive a message, we lose the focus
 * and when the ringer stops playing, we get the focus again.
 * <p>
 * So we must avoid the bug that occurs when the user pauses
 * the player but receives a message - and since after that
 * we get the focus, the player will unpause.
 */
public void onAudioFocusChange(int focusChange) {

    switch (focusChange) {

        // Yay, gained audio focus! Either from losing it for
        // a long or short periods of time.
        case AudioManager.AUDIOFOCUS_GAIN:

            if (player == null)
                initMusicPlayer();

            if (pausedTemporarilyDueToAudioFocus) {
                pausedTemporarilyDueToAudioFocus = false;
                unpausePlayer();
            }

            if (loweredVolumeDueToAudioFocus) {
                loweredVolumeDueToAudioFocus = false;
                player.setVolume(1.0f, 1.0f);
            }
            break;

        // Damn, lost the audio focus for a (presumable) long time
        case AudioManager.AUDIOFOCUS_LOSS:
            stopMusicPlayer();
            break;

        // Just lost audio focus but will get it back shortly
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:

            if (!isPaused()) {
                pausePlayer();
                pausedTemporarilyDueToAudioFocus = true;
            }
            break;

        // Temporarily lost audio focus but I can keep it playing
        // at a low volume instead of stopping completely
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            Log.w(TAG, "audiofocus loss transient can duck");

            player.setVolume(0.1f, 0.1f);
            loweredVolumeDueToAudioFocus = true;
            break;
    }
}
 
源代码20 项目: Muzesto   文件: MusicService.java
@Override
public void handleMessage(final Message msg) {
    final MusicService service = mService.get();
    if (service == null) {
        return;
    }

    synchronized (service) {
        switch (msg.what) {
            case FADEDOWN:
                mCurrentVolume -= .05f;
                if (mCurrentVolume > .2f) {
                    sendEmptyMessageDelayed(FADEDOWN, 10);
                } else {
                    mCurrentVolume = .2f;
                }
                service.mPlayer.setVolume(mCurrentVolume);
                break;
            case FADEUP:
                mCurrentVolume += .01f;
                if (mCurrentVolume < 1.0f) {
                    sendEmptyMessageDelayed(FADEUP, 10);
                } else {
                    mCurrentVolume = 1.0f;
                }
                service.mPlayer.setVolume(mCurrentVolume);
                break;
            case SERVER_DIED:
                if (service.isPlaying()) {
                    final TrackErrorInfo info = (TrackErrorInfo) msg.obj;
                    service.sendErrorMessage(info.mTrackName);


                    service.removeTrack(info.mId);
                } else {
                    service.openCurrentAndNext();
                }
                break;
            case TRACK_WENT_TO_NEXT:
                service.setAndRecordPlayPos(service.mNextPlayPos);
                service.setNextTrack();
                if (service.mCursor != null) {
                    service.mCursor.close();
                    service.mCursor = null;
                }
                service.updateCursor(service.mPlaylist.get(service.mPlayPos).mId);
                service.notifyChange(META_CHANGED);
                service.updateNotification();
                break;
            case TRACK_ENDED:
                if (service.mRepeatMode == REPEAT_CURRENT) {
                    service.seek(0);
                    service.play();
                } else {
                    service.gotoNext(false);
                }
                break;
            case RELEASE_WAKELOCK:
                service.mWakeLock.release();
                break;
            case FOCUSCHANGE:
                if (D) Log.d(TAG, "Received audio focus change event " + msg.arg1);
                switch (msg.arg1) {
                    case AudioManager.AUDIOFOCUS_LOSS:
                    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                        if (service.isPlaying()) {
                            service.mPausedByTransientLossOfFocus =
                                    msg.arg1 == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT;
                        }
                        service.pause();
                        break;
                    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                        removeMessages(FADEUP);
                        sendEmptyMessage(FADEDOWN);
                        break;
                    case AudioManager.AUDIOFOCUS_GAIN:
                        if (!service.isPlaying()
                                && service.mPausedByTransientLossOfFocus) {
                            service.mPausedByTransientLossOfFocus = false;
                            mCurrentVolume = 0f;
                            service.mPlayer.setVolume(mCurrentVolume);
                            service.play();
                        } else {
                            removeMessages(FADEDOWN);
                            sendEmptyMessage(FADEUP);
                        }
                        break;
                    default:
                }
                break;
            default:
                break;
        }
    }
}