当前位置: 首页>>代码示例>>Java>>正文


Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT属性代码示例

本文整理汇总了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;
    }
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:26,代码来源:MediaPlayerService.java

示例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;
    }
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:19,代码来源:JCVideoPlayer.java

示例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;
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:16,代码来源:VoiceMediator.java

示例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();
    }
}
 
开发者ID:rahularity,项目名称:miwokapp,代码行数:22,代码来源:ColorsActivity.java

示例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;
    }
}
 
开发者ID:qq1210514049,项目名称:ListVideoPlayer,代码行数:24,代码来源:ListVideoPlayer.java

示例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;
    }
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:20,代码来源:JCVideoPlayer.java

示例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;
	}
}
 
开发者ID:NiciDieNase,项目名称:chaosflix-leanback,代码行数:26,代码来源:OverlayFragment.java

示例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;
    }
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:26,代码来源:PlaybackOverlayFragment.java

示例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();
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:12,代码来源:BasePlayback.java

示例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;
    }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:38,代码来源:PlayerService.java

示例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();
    }
}
 
开发者ID:hshah11,项目名称:Lang_Tutor,代码行数:12,代码来源:MarathiPhrasesFragment.java

示例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;
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:35,代码来源:VolumeHelper.java

示例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();
    }
}
 
开发者ID:hshah11,项目名称:Lang_Tutor,代码行数:14,代码来源:MarathiNumbersFragment.java

示例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();
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:28,代码来源:AudioPreview.java

示例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;
    }
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:27,代码来源:PlayerManager.java


注:本文中的android.media.AudioManager.AUDIOFOCUS_LOSS_TRANSIENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。