使用AudioServices监听硬件音量。当音量变为零时,将 MPVolumeSlider 的 alpha 设置为零并将您自己禁用的 UISlider 放在相同的位置。为您的滑块蒙皮,使其看起来像音量滑块。
AudioSessionAddPropertyListener( kAudioSessionProperty_CurrentHardwareOutputVolume , ... );
kAudioSessionProperty_AudioRouteChanged
也可能有用。
如果您遍历 MPVolumeView 下的视图层次结构,您应该会找到一个 UISlider。如果没有,或者如果它被隐藏,您就知道静音字符串正在显示。
编辑:
这描述了侦听器的函数原型。要将消息传递给您的类的实例,请执行以下操作:
void MyPropertyListener ( void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData );
void MyPropertyListener ( void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData ) {
if ( inID == kAudioSessionProperty_CurrentHardwareOutputVolume ) {
Float32 volume = *(Float32 *)inData;
[(MyDelegateClass *)inClientData hardwareVolumeChanged:volume];
}
}
AudioSessionAddPropertyListener( kAudioSessionProperty_CurrentHardwareOutputVolume ,
MyPropertyListener , aDelegateInstance );