这是伴随音频服务功能AudioServicesSetProperty的模糊。它有点过头了。有人能给我一个如何实际使用它的例子。感谢。
AudioServicesSetProperty设置 指定系统声音的值 服务财产。
OSStatus AudioServicesSetProperty(
AudioServicesPropertyID inPropertyID, UInt32 inSpecifierSize, const void * inSpecifier, UInt32 inPropertyDataSize, const void * inPropertyData);参数:
inPropertyID:其值为的属性 你想设置。
inSpecifierSize:缓冲区的大小 inSpecifier指出 参数。如果没有说明符则传递0 缓冲是必需的。
inSpecifier:指向说明符的指针 缓冲区,如果需要这样的缓冲区 由你想要的财产 信息。如果没有说明符,则传递NULL 是必需的。
inPropertyDataSize:大小,以字节为单位, 的指向的缓冲区 outPropertyData参数。
inPropertyData:您的属性值 想要设置。
答案 0 :(得分:6)
如果您使用系统声音服务机制播放短暂的系统声音(短于30秒)(代码如下所示)
#include <AudioToolbox/AudioToolbox.h>
SystemSoundID aSoundID;
/* Setup */
SystemSoundID aSoundID;
OSStatus error =
AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) { // success
_soundID = aSoundID;
}
/* Play */
AudioServicesPlaySystemSound(aSoundID);
/* Dispose */
AudioServicesDisposeSystemSoundID(aSoundID);
您可以使用 AudioServicesSetProperty 使用此功能设置两个属性。
他们是: kAudioServicesPropertyIsUISound ='isui', kAudioServicesPropertyCompletePlaybackIfAppDies ='ifdi'
kAudioServicesPropertyIsUISound ,如果设置为1表示对于由inSpecifier参数传递的系统声音指定的音频文件,System Sound服务器会尊重Sound Effects首选项中的用户设置,当用户关闭声音效果时,它会静音。
默认情况下,此属性设置为1。将其设置为0,以便在传递给AudioServicesPlaySystemSound时始终播放系统声音,无论用户在声音首选项中的设置如何。
kAudioServicesPropertyCompletePlaybackIfAppDies ,如果设置为1,则表示即使客户端应用程序终止,inSpecifier参数中传递的系统声音指定的音频文件也应该完成播放。例如,如果用户退出或应用程序在声音播放时意外终止,则可能发生这种情况。默认值为0.也就是说,如果您希望声音完成播放,则必须将此属性的值显式设置为1,即使应用程序终止也是如此。
编辑:重新阅读您的问题后,似乎可能更多“我如何设置属性”而不是“这件事做什么”在这种情况下,以下将更多有用:
假设您按照我上面的指定设置了声音,您可以通过执行以下操作将此特定SystemSoundID对象设置为忽略手机侧面的“静音”设置:
UInt32 flag = 0;
err = AudioServicesSetProperty(kAudioServicesPropertyIsUISound,
sizeof(UInt32),
&aSoundID,
sizeof(UInt32),
&flag);