欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Android 視頻播放時停止后臺運行的方法

 更新時間:2017年06月01日 09:53:24   作者:iGoach  
這篇文章主要介紹了詳解Android 視頻播放時停止后臺運行的方法的相關資料,需要的朋友可以參考下

詳解Android 視頻播放時停止后臺運行的方法

在項目中,遇到了視頻播放,可是后臺播放的音樂也同時播放,我們要的效果肯定是視頻播放的時候,音樂暫停,視頻播放完了我們就繼續(xù)播放音樂,于是就找到了這個方法。

/**@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; 
} 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

最新評論