kAudioServicesPropertyCompletePlaybackIfAppDies

System Sound Servicesを調べていて、謎なPropertyがあることを知りました。

AudioServicesSetPropertyで
Property : kAudioServicesPropertyCompletePlaybackIfAppDies
value : 1
をセットすると、アプリが終了した後も音を鳴らし続けることができます。
System Sound Servicesは最大で30秒の長さのサウンドファイルが扱えるので
最大で30秒、アプリを終了しても音が鳴り続けます。

これは何のために存在するのだろう。
警告音が途中で終わらないためか?
アラーム系アプリを開発する人は使えるかもですね。(どんなアプリだ)

こんな感じで動かします。お試しあれ。

Example

NSString *path = [[NSBundle mainBundle] pathForResource:@"FM" ofType:@"aif"];
NSURL *fileURL = [NSURL fileURLWithPath:path];

OSStatus err;
err = AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &systemSoundID);
if(err){
    NSLog(@"AudioServicesCreateSystemSoundID err = %d",err);
    exit(1);
}

UInt32 flag = 1;
err = AudioServicesSetProperty(kAudioServicesPropertyCompletePlaybackIfAppDies,
                               sizeof(UInt32),
                               &systemSoundID,
                               sizeof(UInt32),
                               &flag);
if(err){
    NSLog(@"AudioServicesSetProperty err = %d",err);
}

AudioServicesPlaySystemSound(systemSoundID);
exit(0);

One Comment

  1. Using audio services to play alert sound | Indie iPhone Development Blog said:

    [...] which is an important feature for this use.  I was able to find how to set this property on Nagano’s blog.  Not sure what most of the page says but the language of Objective C is universal. Remember to [...]

Leave a Reply