2009-04-11 30 views
1

这是伴随音频服务功能AudioServicesSetProperty的声音。它有点凌驾于我的头上。有人能给我一个如何实际使用这个例子。谢谢。有关音频服务功能的帮助

AudioServicesSetProperty设置指定系统声音 服务属性 值。

OSStatus AudioServicesSetProperty(
AudioServicesPropertyID inPropertyID, UInt32的inSpecifierSize, 常量无效* inSpecifier, UInt32的inPropertyDataSize, 常量无效* inPropertyData);

参数:

inPropertyID:该物业 要设置其值。

inSpecifierSize:参数inSpecifier 指向的缓冲区大小 。如果不需要说明符 缓冲区,则传递0。

inSpecifier:指向缓冲区的指针 ,如果需要这样的缓冲区 由您希望获得 信息的属性。如果不需要说明符 ,则传递NULL。

inPropertyDataSize:outPropertyData参数指向的缓冲区的大小,以字节为单位, 。

inPropertyData:您想要设置的属性值 。

+1

这个问题似乎有点倒退。你想做什么?你不明白什么? – 2009-04-11 02:23:03

回答

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。无论用户在声音首选项中如何设置,系统声音在传递到AudioServicesPlaySystemSound时都将其设置为0。

kAudioServicesPropertyCompletePlaybackIfAppDies,如果它被设置为1,意味着由系统指定的音频文件中的参数inSpecifier声音传递要完成打,即使客户端应用程序终止。例如,如果用户退出或应用程序在播放声音时意外终止,则可能发生这种情况。默认值为0.也就是说,如果即使应用程序终止,也希望声音完成播放,您必须明确地将此属性的值设置为1。

编辑:,在重读你的问题,现在看来,这可能是更多的“我如何设置属性”比“这是什么东西做的”这样的话,下面会更加有用:

假设你设置的声音就像我上面规定的,你可以设置这个特殊的SystemSoundID对象做忽略对手机侧面的“沉默”的设置如下:

UInt32 flag = 0; 
err = AudioServicesSetProperty(kAudioServicesPropertyIsUISound, 
           sizeof(UInt32), 
           &aSoundID, 
           sizeof(UInt32), 
           &flag); 
0

我不能让尽管设置了mmc建议的kAudioServicesPropertyIsUISound,该应用仍可以在静音模式下播放音频。

其他任何人都有幸运?