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


Java AudioManager.OnAudioFocusChangeListener方法代码示例

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

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

示例3: requestAudioFocus

import android.media.AudioManager; //导入方法依赖的package包/类
private int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint) {
    return mAudioManager.requestAudioFocus(l, streamType, durationHint);
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:4,代码来源:PlayerAudioManager.java

示例4: abandonAudioFocus

import android.media.AudioManager; //导入方法依赖的package包/类
private int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l) {
    return mAudioManager.abandonAudioFocus(l);
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:4,代码来源:PlayerAudioManager.java


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