掀浪云网站建设,鞍山网站设计制作,wordpress默认模版,开展网络营销的企业问题描述#xff1a; 自定义按键音播放#xff0c;在Launcher上按 上下左右和OK 按键发现会播放两次按键提示音#xff0c;其他的都是正常的。 首先找一下播放的是哪个文件#xff0c;在下面的README中有定义
frameworks/base/data/sounds/README.txtTouch sounds
-------… 问题描述 自定义按键音播放在Launcher上按 上下左右和OK 按键发现会播放两次按键提示音其他的都是正常的。 首先找一下播放的是哪个文件在下面的README中有定义
frameworks/base/data/sounds/README.txtTouch sounds
------------effects/Effect_Tick.oggold, referenced by AudioPackage[2345].mk OriginalAudio.mkeffects/ogg/Effect_Tick.oggnew, referenced by AudioPackage[6789].mk AudioPackage7alt.mk AudioPackage10.mkeffects/ogg/Effect_Tick_48k.oggoggdec -o temp.wav ogg/Effect_Tick.oggsox temp.wav -r 48000 temp48k.wavoggenc -b 80 -o ogg/Effect_Tick_48k.ogg temp48k.waveffects/wav/Effect_Tick.wavdoes not appear to be related to the other files in any obvious way也就是触摸和点击事件都是播放的 Effect_Tick 这个音频文件。直接检索这个在哪里调用。 xml文件是为了替换默认声音资源并且可以看到很多需要的如上下左右都在这里定义了并且播放的都是Effect_Tick。
framework/base/core/res/res/xml/audio_assets.xml!-- Mapping of UI sound effects to audio assets under /system/media/audio/ui.Modify this file to override default sound assets.
--audio_assets version1.0asset idFX_KEY_CLICK fileEffect_Tick.ogg/asset idFX_FOCUS_NAVIGATION_UP fileEffect_Tick.ogg/asset idFX_FOCUS_NAVIGATION_DOWN fileEffect_Tick.ogg/asset idFX_FOCUS_NAVIGATION_LEFT fileEffect_Tick.ogg/asset idFX_FOCUS_NAVIGATION_RIGHT fileEffect_Tick.ogg/asset idFX_KEYPRESS_STANDARD fileKeypressStandard.ogg/asset idFX_KEYPRESS_SPACEBAR fileKeypressSpacebar.ogg/asset idFX_KEYPRESS_DELETE fileKeypressDelete.ogg/asset idFX_KEYPRESS_RETURN fileKeypressReturn.ogg/asset idFX_KEYPRESS_INVALID fileKeypressInvalid.ogg/asset idFX_BACK
再根据 SoundEffectsHelper.java 找到实现播放的方法 void playSoundEffect(int effect, int volume)
其实是在 AudioService.java 定义的 /** see AudioManager#playSoundEffect(int) */public void playSoundEffect(int effectType) {playSoundEffectVolume(effectType, -1.0f);}/** see AudioManager#playSoundEffect(int, float) */public void playSoundEffectVolume(int effectType, float volume) {// do not try to play the sound effect if the system stream is mutedif (isStreamMute(STREAM_SYSTEM)) {return;}if (effectType AudioManager.NUM_SOUND_EFFECTS || effectType 0) {Log.w(TAG, AudioService effectType value effectType out of range);return;}sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SENDMSG_QUEUE,effectType, (int) (volume * 1000), null, 0);} 根据注释可以确定是通过 AudioManager 调用的。目前已经确定了播放按键提示音的调用方法。再次检索。
是在这里实现的播放 Overridepublic void playSoundEffect(SoundEffectConstants.SoundEffect int effectId) {checkThread();try {final AudioManager audioManager getAudioManager();if (mFastScrollSoundEffectsEnabled SoundEffectConstants.isNavigationRepeat(effectId)) {audioManager.playSoundEffect(SoundEffectConstants.nextNavigationRepeatSoundEffectId());return;}if (true) {Log.e(TAG, lichang playSoundEffect avoid click tone);return;}switch (effectId) {case SoundEffectConstants.CLICK:audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);return;case SoundEffectConstants.NAVIGATION_DOWN:case SoundEffectConstants.NAVIGATION_REPEAT_DOWN:audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN);return;case SoundEffectConstants.NAVIGATION_LEFT:case SoundEffectConstants.NAVIGATION_REPEAT_LEFT:audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT);return;case SoundEffectConstants.NAVIGATION_RIGHT:case SoundEffectConstants.NAVIGATION_REPEAT_RIGHT:audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT);return;case SoundEffectConstants.NAVIGATION_UP:case SoundEffectConstants.NAVIGATION_REPEAT_UP:audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP);return;default:throw new IllegalArgumentException(unknown effect id effectId not defined in SoundEffectConstants.class.getCanonicalName());}} catch (IllegalStateException e) {// Exception thrown by getAudioManager() when mView is nullLog.e(mTag, FATAL EXCEPTION when attempting to play sound effect: e);e.printStackTrace();}}直接屏蔽掉即可。或者其实从 framework/base/core/res/res/xml/audio_assets.xml 也可以看到有方向键等音频资源可以通过检索直接定位到位置。 只在framework下检索是因为对日志进行分析过滤Audiotrack
11:42:03.414 AudioTrack I start mClientAttributionSource.uid:1000 mClientAttributionSource.pid:1013 mSessionId:129 app name:system_server 11:42:03.433 AudioTrack I start mClientAttributionSource.uid:1000 mClientAttributionSource.pid:1013 mSessionId:145 app name:system_server 11:42:03.525 AudioTrack I stop mClientAttributionSource.uid:1000 mClientAttributionSource.pid:1013 mSessionId:129 app name:system_server 11:42:03.553 AudioTrack I stop mClientAttributionSource.uid:1000 mClientAttributionSource.pid:1013 mSessionId:145 app name:system_server 可以看到这两次声音播放都是 system_server 这个进程调用的。 补充由于是自定义按键音播放的因此需要实现原生的按键音开关功能增加条件 if (System.getInt(context.getContentResolver(), System.SOUND_EFFECTS_ENABLED, 1) 1) playEffect(context); 结束