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


Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK属性代码示例

本文整理汇总了Java中android.media.AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK属性的具体用法?Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK怎么用?Java AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.media.AudioManager的用法示例。


在下文中一共展示了AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS:
            eventEmitter.audioFocusChanged(false);
            break;
        case AudioManager.AUDIOFOCUS_GAIN:
            eventEmitter.audioFocusChanged(true);
            break;
        default:
            break;
    }

    if (player != null) {
        if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
            // Lower the volume
            player.setVolume(0.8f);
        } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
            // Raise it back to normal
            player.setVolume(1);
        }
    }
}
 
开发者ID:12d,项目名称:react-native-videoplayer,代码行数:23,代码来源:ReactExoplayerView.java

示例2: 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

示例3: 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:ad-on-is,项目名称:chilly,代码行数:26,代码来源:PlaybackOverlayFragment.java

示例4: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    Log.e(TAG, "audioFocusChangeListener.onAudioFocusChange>>>>>>>>>>>>>>>>>>" + focusChange);
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
            if (mPlayer != null) {
                volScalar = ((float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)) / audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
                // Log.i("LingJu", "获取媒体音量:" + volScalar);
                mPlayer.setVolume(0.2f, 0.2f);

            }
            break;
        }
        case AudioManager.AUDIOFOCUS_GAIN:
            if (mPlayer != null) {
                // Log.i("LingJu", "获取焦点后设置播放音量:" + volScalar);
                volScalar = volScalar == 0 ? 0.5f : volScalar;
                mPlayer.setVolume(volScalar, volScalar);
            }
            break;
        default:
            break;
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:26,代码来源:LingjuAudioPlayer.java

示例5: 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,代码来源:NumbersFragment.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-leanback,代码行数:26,代码来源:OverlayFragment.java

示例7: 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

示例8: 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

示例9: onAudioFocusChange

public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        // Permanent loss of audio focus
        // Pause playback immediately
        // mediaController.getTransportControls().pause();
        pausePlayer();
        // Wait 30 seconds before stopping playback
        /*
        mHandler.postDelayed(new Runnable() {
                                 @Override
                                 public void run() {
                                     currentTrackPlayer.stop();
                                 }
                             },
                TimeUnit.SECONDS.toMillis(30));
                */
    }
    else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
        // Pause playback
        pausePlayer();
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // Lower the volume, keep playing
        if (currentTrackPlayer != null)
            currentTrackPlayer.setVolume(0.25f, 0.25f);
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        // Your app has been granted audio focus again
        // Raise volume to normal, restart playback if necessary
        if (currentTrackPlayer != null)
            currentTrackPlayer.setVolume(1.0f, 1.0f);
    }
}
 
开发者ID:n76,项目名称:Symphony,代码行数:31,代码来源:MusicService.java

示例10: 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,代码来源:GujaratiNumbersFragment.java

示例11: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        if (isPlayingAudio(getPlayingMessageObject()) && !isAudioPaused()) {
            pauseAudio(getPlayingMessageObject());
        }
        hasAudioFocus = 0;
        audioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        audioFocus = AUDIO_FOCUSED;
        if (resumeAudioOnFocusGain) {
            resumeAudioOnFocusGain = false;
            if (isPlayingAudio(getPlayingMessageObject()) && isAudioPaused()) {
                playAudio(getPlayingMessageObject());
            }
        }
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        audioFocus = AUDIO_NO_FOCUS_CAN_DUCK;
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
        audioFocus = AUDIO_NO_FOCUS_NO_DUCK;
        if (isPlayingAudio(getPlayingMessageObject()) && !isAudioPaused()) {
            pauseAudio(getPlayingMessageObject());
            resumeAudioOnFocusGain = true;
        }
    }
    setPlayerVolume();
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:27,代码来源:MediaController.java

示例12: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusState) {
    //Invoked when the audio focus of the system is updated.
    switch (focusState) {
        case AudioManager.AUDIOFOCUS_GAIN:
            // resume playback
            if (mediaPlayer == null) initMediaPlayer();
            else if (!mediaPlayer.isPlaying()) mediaPlayer.start();
            mediaPlayer.setVolume(1.0f, 1.0f);
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            // Lost focus for an unbounded amount of time: stop playback and release media player
            if (mediaPlayer.isPlaying()) mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            // Lost focus for a short time, but we have to stop
            // playback. We don't release the media player because playback
            // is likely to resume
            if (mediaPlayer.isPlaying()) mediaPlayer.pause();
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // Lost focus for a short time, but it's ok to keep playing
            // at an attenuated level
            if (mediaPlayer.isPlaying()) mediaPlayer.setVolume(0.1f, 0.1f);
            break;
    }
}
 
开发者ID:CommonsLab,项目名称:CommonsLab,代码行数:29,代码来源:MediaPlayerService.java

示例13: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
        try {
            stopPlaying();
            mAudioManagerHelper.setHasAudioFocus(false);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        mAudioManagerHelper.setAudioDucked(true);
        mAudioManagerHelper.setTargetVolume(5);
        mAudioManagerHelper.setStepDownIncrement(1);
        mAudioManagerHelper.setCurrentVolume(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
        mAudioManagerHelper.setOriginalVolume(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
        mHandler.post(duckDownVolumeRunnable);

    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        if (mAudioManagerHelper.isAudioDucked()) {
            mAudioManagerHelper.setTargetVolume(mAudioManagerHelper.getOriginalVolume());
            mAudioManagerHelper.setStepUpIncrement(1);
            mAudioManagerHelper.setCurrentVolume(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
            mHandler.post(duckUpVolumeRunnable);
            mAudioManagerHelper.setAudioDucked(false);
        } else {
            mAudioManagerHelper.setHasAudioFocus(true);
        }
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        if (mMediaPlayer1 != null) {
            stopPlaying();
        }
        mAudioManagerHelper.setHasAudioFocus(false);
    }

}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:36,代码来源:MusicService.java

示例14: 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

示例15: 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


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