之前是使用静音操作计数的方式的,就是只有静音计数为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); } }这个方法就是一下一下调音量的
新闻热点
疑难解答