之前是使用靜音操作計數的方式的,就是只有靜音計數為0時才會取消靜音.每個i進程可以設一次靜音.在當進程死亡時,會自動取消靜音.當然靜音也會發同樣的廣播,只是音量為0的廣播.
但是后面就是一個AudioService#VolumeState#mIsMuted成員保存是否靜音的.而不用基數,就是每個應用都可以控制靜音和不靜音.
/** * Mute or unmute an audio stream. * <p> * This method should only be used by applications that replace the * platform-wide management of audio settings or the main telephony * application. * <p> * This method has no effect if the device implements a fixed volume policy * as indicated by {@link #isVolumeFixed()}. * <p> * This method was dePRecated in API level 22. Prior to API level 22 this * method had significantly different behavior and should be used carefully. * The following applies only to pre-22 platforms: * <ul> * <li>The mute command is protected against client process death: if a * process with an active mute request on a stream dies, this stream will be * unmuted automatically.</li> * <li>The mute requests for a given stream are cumulative: the AudioManager * can receive several mute requests from one or more clients and the stream * will be unmuted only when the same number of unmute requests are * received.</li> * <li>For a better user experience, applications MUST unmute a muted stream * in onPause() and mute is again in onResume() if appropriate.</li> * </ul> * * @param streamType The stream to be muted/unmuted. * @param state The required mute state: true for mute ON, false for mute * OFF * @see #isVolumeFixed() * @deprecated Use {@link #adjustStreamVolume(int, int, int)} with * {@link #ADJUST_MUTE} or {@link #ADJUST_UNMUTE} instead. */ @Deprecated public void setStreamMute(int streamType, boolean state)可以看到上面的提示這個方法已經被淘汰在,這個方法可以用,但好像之可以讓用戶應用用于自己應用的控制,代替整個平臺范圍的音量設置.當設備實現了一個fixed volume policy時,這個方法會失效....用adjuststreamVolume(int, int, int)代替這個方法.就是說不用計數了./** * Adjusts the volume of a particular stream by one step in a direction. * <p> * This method should only be used by applications that replace the platform-wide * management of audio settings or the main telephony application. * * @param streamType The stream type to adjust. One of {@link #STREAM_VOICE_CALL}, * {@link #STREAM_SYSTEM}, {@link #STREAM_RING}, {@link #STREAM_MUSIC} or * {@link #STREAM_ALARM} * @param direction The direction to adjust the volume. One of * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or * {@link #ADJUST_SAME}. * @param flags One or more flags. * @see #setStreamVolume(int, int, int) * @see #adjustVolume(int, int) */ public void adjustStreamVolume(int streamType, int direction, int flags) { IAudioService service = getService(); try { service.adjustStreamVolume(streamType, direction, flags, getContext().getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustStreamVolume", e); } }這個方法就是一下一下調音量的
新聞熱點
疑難解答