本文整理汇总了Java中android.media.AudioManager.AUDIOFOCUS_LOSS_TRANSIENT属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT属性的具体用法?Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT怎么用?Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.AUDIOFOCUS_LOSS_TRANSIENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange){
case AudioManager.AUDIOFOCUS_GAIN:
//获取音频焦点
LogUtils.e(TAG,"AUDIOFOCUS_GAIN");
break;
case AudioManager.AUDIOFOCUS_LOSS:
//永久失去 音频焦点
LogUtils.e(TAG,"AUDIOFOCUS_LOSS");
pause();
abandonFocus();//放弃音频焦点
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
//暂时失去 音频焦点,并会很快再次获得。必须停止Audio的播放,但是因为可能会很快再次获得AudioFocus,这里可以不释放Media资源
LogUtils.e(TAG,"AUDIOFOCUS_LOSS_TRANSIENT");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
//暂时失去 音频焦点 ,但是可以继续播放,不过要在降低音量。
LogUtils.e(TAG,"AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
break;
default:
LogUtils.e(TAG,"default"+ focusChange);
break;
}
}
示例2: 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;
}
}
示例3: 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;
}
}
示例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: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
onPause();
Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
try {
if (MediaManager.instance().mediaPlayer != null &&
MediaManager.instance().mediaPlayer.isPlaying()) {
MediaManager.instance().mediaPlayer.pause();
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
break;
}
}
示例6: 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 != null &&
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;
}
}
示例7: 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;
}
}
示例8: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
abandonAudioFocus();
pause();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
if (mGlue.isMediaPlaying()) {
pause();
mPauseTransient = true;
}
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
mPlayer.mute(true);
break;
case AudioManager.AUDIOFOCUS_GAIN:
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
if (mPauseTransient) {
play();
}
mPlayer.mute(false);
break;
}
}
示例9: onAudioFocusChange
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
focusState = AUDIO_FOCUSED;
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
focusState = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK;
}
updatePlayer();
}
示例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
@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();
}
}
示例12: onAudioFocusChange
@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;
}
}
示例13: 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();
}
}
示例14: onAudioFocusChange
public void onAudioFocusChange(int focusChange) {
if (mPlayer == null) {
// this activity has handed its MediaPlayer off to the next activity
// (e.g. portrait/landscape switch) and should abandon its focus
mAudioManager.abandonAudioFocus(this);
return;
}
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
mPausedByTransientLossOfFocus = false;
mPlayer.pause();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
if (mPlayer.isPlaying()) {
mPausedByTransientLossOfFocus = true;
mPlayer.pause();
}
break;
case AudioManager.AUDIOFOCUS_GAIN:
if (mPausedByTransientLossOfFocus) {
mPausedByTransientLossOfFocus = false;
start();
}
break;
}
updatePlayPause();
}
示例15: onAudioFocusChange
@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;
}
}