/**<p>項目名:HFIOT_integration</p> * <p>包名: com.nb82.bean</p> * <p>文件名:AudioManagerBean.java</p> * <p>版本信息: 2.1.0</p> * <p>日期: 2015/5/26/16:48.</p> * Copyright (c) 2015幫你公司-版權全部 */ package com.nb82.bean; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.util.Log; /** * <p>名稱:com.nb82.bean.AudioManagerBean</p> * <p>描述:系統音量變化監聽</p> * <pre> * 處理系統的音量變化的操做 * </pre> * * @author 鮑建明 * @version 2.1.0 * @date 2015/5/26/16:48 */ public class AudioManager { private android.media.AudioManager mAudioManager; public AudioManager(Context context){ IntentFilter filter = new IntentFilter() ; filter.addAction("android.media.VOLUME_CHANGED_ACTION") ; VolumeReceiver vr = new VolumeReceiver(); context.registerReceiver(vr, filter); //音量控制,初始化定義 mAudioManager = (android.media.AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } /** * 顯示系統聲音進度條 */ public void showVolume(){ mAudioManager.adjustStreamVolume(android.media.AudioManager.STREAM_MUSIC, android.media.AudioManager.FLAG_SHOW_UI, android.media.AudioManager.FX_FOCUS_NAVIGATION_UP); } /** * 聲音變化廣播器 */ class VolumeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //若是音量發生變化則更改seekbar的位置 if(intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")){ Log.w("android.media.VOLUME_CHANGED_ACTION", "用戶調節聲音了..."); int currentVolume = mAudioManager.getStreamVolume(android.media.AudioManager.STREAM_MUSIC); //TODO 根據當前音量進行其餘的業務操做 } } } }