zoukankan      html  css  js  c++  java
  • 停止、恢复 背景音乐的播放

    在执行录音操作时,我们希望可以将酷狗等后台播放的音乐停掉,在录音完成后再恢复播放,可以使用以下代码:

    	/**@param bMute 值为true时为关闭背景音乐。*/
    	@TargetApi(Build.VERSION_CODES.FROYO)
    	public static boolean muteAudioFocus(Context context, boolean bMute) {
    		if(context == null){
    			Log.d("ANDROID_LAB", "context is null.");
    			return false;
    		}
    		if(!VersionUtils.isrFroyo()){
    			// 2.1以下的版本不支持下面的API:requestAudioFocus和abandonAudioFocus
    			Log.d("ANDROID_LAB", "Android 2.1 and below can not stop music");
    			return false;
    		}
    		boolean bool = false;
    		AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    		if(bMute){
    			int result = am.requestAudioFocus(null,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    			bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
    		}else{
    			int result = am.abandonAudioFocus(null);
    			bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
    		}
    		Log.d("ANDROID_LAB", "pauseMusic bMute="+bMute +" result="+bool);
    		return bool;
    	}
  • 相关阅读:
    php && 逻辑与运算符使用说明
    php无穷递归算法
    PHP foreach 用法
    centos安装g++
    php 编译中apxs
    shutdown()
    C语言strtok()函数:字符串分割
    细谈select函数(C语言)
    setsockopt的作用
    STL之七:STL各种容器的使用时机详解
  • 原文地址:https://www.cnblogs.com/krislight1105/p/4245012.html
Copyright © 2011-2022 走看看