本文整理汇总了Java中android.media.AudioManager.AUDIOFOCUS_LOSS属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.AUDIOFOCUS_LOSS属性的具体用法?Java AudioManager.AUDIOFOCUS_LOSS怎么用?Java AudioManager.AUDIOFOCUS_LOSS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.AUDIOFOCUS_LOSS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
releaseAllVideos();
Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
if (JCMediaManager.instance().mediaPlayer.isPlaying()) {
JCMediaManager.instance().mediaPlayer.pause();
}
Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
break;
}
}
示例2: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
Log.i("LingJu", "焦点状态:" + focusChange);
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
isFocus = false;
mAudioManager.abandonAudioFocus(mFocusChangeListener);
break;
case AudioManager.AUDIOFOCUS_GAIN:
Log.i("LingJu", "MainActivity onAudioFocusChange()");
isFocus = true;
break;
}
}
示例3: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
releaseAllVideos();
Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
try {
if (JZMediaManager.isPlaying()) {
JZMediaManager.pause();
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
break;
}
}
示例4: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
// The AUDIOFOCUS_LOSS_TRANSIENT case means that we've lost audio focus for a
// short amount of time. The AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK case means that
// our app is allowed to continue playing sound but at a lower volume. We'll treat
// both cases the same way because our app is playing short sound files.
// Pause playback and reset player to the start of the file. That way, we can
// play the word from the beginning when we resume playback.
mMediaPlayer.pause();
mMediaPlayer.seekTo(0);
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// The AUDIOFOCUS_GAIN case means we have regained focus and can resume playback.
mMediaPlayer.start();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
// The AUDIOFOCUS_LOSS case means we've lost audio focus and
// Stop playback and clean up resources
releaseMediaPlayer();
}
}
示例5: onFocusChange
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());
}
}
示例6: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
abandonAudioFocus();
pause();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
if (mHelper.isMediaPlaying()) {
pause();
mPauseTransient = true;
}
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
mCallback.mute(true);
break;
case AudioManager.AUDIOFOCUS_GAIN:
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
if (mPauseTransient) {
play();
}
mCallback.mute(false);
break;
}
}
示例7: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
if (mPlayOnAudioFocus && !isPlaying()) {
play();
} else if (isPlaying()) {
setVolume(MEDIA_VOLUME_DEFAULT);
}
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);
stop();
break;
}
}
示例8: onAudioFocusChange
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) :
if(sep != null)
sep.setVolume(0.2f);
break;
case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) :
mutePlayer();
break;
case (AudioManager.AUDIOFOCUS_LOSS) :
stopPlaying();
break;
case (AudioManager.AUDIOFOCUS_GAIN) :
unmutePlayer();
break;
default: break;
}
}
示例9: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK){
mMediaPlayer.pause();
mMediaPlayer.seekTo(0);
}
else if (focusChange == AudioManager.AUDIOFOCUS_GAIN){
mMediaPlayer.start();
}
else if(focusChange == AudioManager.AUDIOFOCUS_LOSS){
releaseMediaPlayer();
}
}
示例10: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
// gain of audio focus of unknown duration
case AudioManager.AUDIOFOCUS_GAIN:
if (mPlayback) {
if (mExoPlayer == null) {
initializeExoPlayer();
mExoPlayer.setPlayWhenReady(true);
} else if (mExoPlayer.getPlayWhenReady()) {
mExoPlayer.setPlayWhenReady(true);
}
mExoPlayer.setVolume(1.0f);
}
break;
// loss of audio focus of unknown duration
case AudioManager.AUDIOFOCUS_LOSS:
if (mPlayback && mExoPlayer.getPlayWhenReady()) {
mController.getTransportControls().stop();
}
break;
// transient loss of audio focus
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
if (!mPlayback && mExoPlayer != null && mExoPlayer.getPlayWhenReady()) {
mController.getTransportControls().stop();
}
else if (mPlayback && mExoPlayer != null && mExoPlayer.getPlayWhenReady()) {
mExoPlayer.setPlayWhenReady(false);
}
break;
// temporary external request of audio focus
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
if (mExoPlayer != null && mExoPlayer.getPlayWhenReady()){
mExoPlayer.setVolume(0.1f);
}
break;
}
}
示例11: onAudioFocusChange
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) :
case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) :
case (AudioManager.AUDIOFOCUS_LOSS) :
pauseAllLostFocus();
break;
case (AudioManager.AUDIOFOCUS_GAIN):
resumeAllGainedFocus();
break;
default:
break;
}
}
示例12: onAudioFocusChange
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
// Pause playback
mIsStoppedByFocusLost = isPlaying()|| mIsStoppedByFocusLost;
pause();
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Resume playback
if (!isPlaying()&& mIsStoppedByFocusLost)
start();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
mIsStoppedByFocusLost = isPlaying()|| mIsStoppedByFocusLost;
pause();
}
}
示例13: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
Logger.d(TAG, "onAudioFocusChange. focusChange=", 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 {
Logger.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: ", focusChange);
}
configMediaPlayerState();
}
示例14: onAudioFocusChange
/**
* 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 = PlaybackStateCompat.STATE_PLAYING;
updatePlaybackState();
}
float volume = canDuck ? 0.2f : 1.0f;
mMediaPlayer.setVolume(volume, volume);
}
} else if (mState == PlaybackStateCompat.STATE_PLAYING) {
mMediaPlayer.pause();
mState = PlaybackStateCompat.STATE_PAUSED;
updatePlaybackState();
}
}
示例15: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
mMediaPlayer.pause();
mMediaPlayer.seekTo(0);
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
mMediaPlayer.start();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
releaseMediaPlayer();
}
}