欢迎来到天天文库
浏览记录
ID:57307114
大小:236.23 KB
页数:3页
时间:2020-08-11
《M 调节音量要求发出声音.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、调节音量发出声音功能描述:在调节音量的时候M版本没有声音,客户要求有声音提示功能实现:1.path:frameworksbasepackagesSystemUIsrccomandroidsystemuivolumeVolumeDialogController.java1)importandroid.media.ToneGenerator;//prizecaoshaowei20161024add2)//prizecaoshaowei20161024addstartprivateToneGeneratorplayToneGenerators[];privatein
2、tprevAudibleStreamVolume=-1;//prizecaoshaowei20161024addend3)publicVolumeDialogController(Contextcontext,ComponentNamecomponent){mContext=context.getApplicationContext();.........//prizecaoshaowei20161024addstartif(playToneGenerators==null){playToneGenerators=newToneGenerator[AudioSystem.get
3、NumStreamTypes()];}//prizecaoshaowei20161024addend}4)//prizecaoshaowei20161024addstartprivatevoidonStopSounds(){synchronized(this){intnumStreamTypes=AudioSystem.getNumStreamTypes();for(inti=numStreamTypes-1;i>=0;i--){ToneGeneratortoneGen=playToneGenerators[i];if(toneGen!=null){toneGen.stopTo
4、ne();}}}}//prizecaoshaowei20161024addend5)privatevoidonVolumeChangedW(intstream,intflags){......if(showSilentHint){mCallbacks.onShowSilentHint();}//prizecaoshaowei20161024addstartonStopSounds();if((flags&AudioManager.FLAG_PLAY_SOUND)!=0&&!showSilentHint){if(playToneGenerators[stream]==null){
5、try{playToneGenerators[stream]=newToneGenerator(stream,100);}catch(RuntimeExceptione){Log.d(TAG,"ToneGeneratorconstructorfailedwith"+"RuntimeException:"+e);}}synchronized(this){finalToneGeneratortoneGen=playToneGenerators[stream];if(toneGen!=null){toneGen.startTone(ToneGenerator.TONE_PROP_BE
6、EP);newHandler().postDelayed(newRunnable(){@Overridepublicvoidrun(){onStopSounds();}},150);}}prevAudibleStreamVolume=lastAudibleStreamVolume;}//prizecaoshaowei20161024addendif(changed&&fromKey){Events.writeEvent(mContext,Events.EVENT_KEY,stream,lastAudibleStreamVolume);}}
此文档下载收益归作者所有