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


Java AudioManager.AUDIOFOCUS_LOSS属性代码示例

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

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

示例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;
    }
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:23,代码来源:JZVideoPlayer.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: 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());
    }
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:16,代码来源:FocusRequestChangeListenerImpl.java

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

示例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;
    }
}
 
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:25,代码来源:PlayerAdapter.java

示例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;
    }
}
 
开发者ID:R-a-dio,项目名称:R-a-dio-Amazing-Android-App,代码行数:21,代码来源:RadioService.java

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

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;
    }
}
 
开发者ID:rodrigonsh,项目名称:alerta-fraude,代码行数:14,代码来源:AudioHandler.java

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

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

示例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();
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:36,代码来源:PlaybackManager.java

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


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