views:

599

answers:

2

Hi. This is the blurb accompanying the Audio Services function AudioServicesSetProperty. Its a bit over my head. Can someone give me an example of how to actually use this. Thanks.

AudioServicesSetProperty Sets the value for a specified System Sound Services property.

OSStatus AudioServicesSetProperty (
AudioServicesPropertyID inPropertyID, UInt32 inSpecifierSize, const void *inSpecifier, UInt32 inPropertyDataSize, const void *inPropertyData );

Parameters:

inPropertyID: The property whose value you want to set.

inSpecifierSize: The size of the buffer pointed to by the inSpecifier parameter. Pass 0 if no specifier buffer is required.

inSpecifier: A pointer to a specifier buffer, if such a buffer is required by the property about which you want information. Pass NULL if no specifier is required.

inPropertyDataSize: The size, in bytes, of the buffer pointed to by the outPropertyData parameter.

inPropertyData: The property value you want to set.

+2  A: 

If you are playing a short system sound (shorter than 30 seconds) using the System Sound Services mechanism (code would look something like the following)

#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);

You can use AudioServicesSetProperty to set two properties using this function.

They are: kAudioServicesPropertyIsUISound = 'isui', kAudioServicesPropertyCompletePlaybackIfAppDies = 'ifdi'

kAudioServicesPropertyIsUISound, if it is set to 1 means that, for the audio file specified by a system sound passed in the inSpecifier parameter, the System Sound server respects the user setting in the Sound Effects preference and is silent when the user turns off sound effects.

This property is set to 1 by default. Set it to 0 for the system sound to always play when passed to AudioServicesPlaySystemSound, regardless of the user's setting in sound preferences.

kAudioServicesPropertyCompletePlaybackIfAppDies, if it is set to 1 means that the audio file specified by a system sound passed in the inSpecifier parameter should finish playing even if the client application terminates. This could happen, for example, if the user quits or the application terminates unexpectedly while the sound is playing. The default is 0. That is, you must explicitly set this property’s value to 1 if you want the sound to complete playing even if the application terminates.

EDIT: Upon re-reading your question, it seems it may be more "How do I set a property" than "what does this thing do" In this case, the following will be more useful:

Assuming you set up the sound as I specified above, you could set this particular SystemSoundID object to ignore the "silent" setting on the side of the phone by doing the following:

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

I couldn't get the app to play the audio on silent mode despite setting the kAudioServicesPropertyIsUISound as suggested by mmc.

Any one else has luck with that?

junjie