本文整理汇总了Java中android.media.AudioManager.OnAudioFocusChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.OnAudioFocusChangeListener方法的具体用法?Java AudioManager.OnAudioFocusChangeListener怎么用?Java AudioManager.OnAudioFocusChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.OnAudioFocusChangeListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import android.media.AudioManager; //导入方法依赖的package包/类
public static AudioPlayerManager get(Context context){
if(instance ==null){
instance = new AudioPlayerManager();
instance.context = context;
instance.am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
instance.listener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT){
//Log.e("dd"," AUDIOFOCUS_LOSS_TRANSIENT ---------------------");
if(instance.state == State.playing){
instance.stateBeforeFocusChange = State.playing;
}
instance.pause();
// Pause playback
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
//Log.e("dd"," AUDIOFOCUS_GAIN ---------------------");
if(instance.stateBeforeFocusChange == State.playing){
instance.resume();
}
// Resume playback
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
//Log.e("dd"," AUDIOFOCUS_LOSS ---------------------");
//am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
instance.stop();
// Stop playback
}
}
};
instance.registerHeadsetPlugReceiver();
}
return instance;
}
示例2: AudioHelper
import android.media.AudioManager; //导入方法依赖的package包/类
public AudioHelper(Context context, AudioManager.OnAudioFocusChangeListener listener, Class<? extends BroadcastReceiver> cls) {
this(context, listener);
componentName = new ComponentName(context.getPackageName(), cls.getName());
}
示例3: requestAudioFocus
import android.media.AudioManager; //导入方法依赖的package包/类
private int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint) {
return mAudioManager.requestAudioFocus(l, streamType, durationHint);
}
示例4: abandonAudioFocus
import android.media.AudioManager; //导入方法依赖的package包/类
private int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l) {
return mAudioManager.abandonAudioFocus(l);
}