In this thread Walter asked:
> And is there a more modern (non deprecated) way of playing a sound either from a resource, or from a.AIF file?
Walter as mentioned, NSSound is alive and well. Concerning you latency issue, you might want to experiment
with the AudioToolbox framework where latency can easily be controlled. Here is a quick example that runs
though System sounds using a simple FB delay statement to put a brief pause between each sound. (With the delay
removed, the sounds play almost instantaneously.)
In practice, you would implement an AudioServicesAddSystemSoundCompletion callback function that would
detect when a sound was complete. However, if your sounds are just short alerts, you may find this suitable as is.
Of course to get the CFURLRef of a sound bundled with your application, you would use:
include resources "MySound.aiff"
dim as CFURLRef mySound
mySound = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), @"MySound", @"aiff", 0 )
Ken
include library "AudioToolbox/AudioToolbox.h"
#if ndef _DEFINEDINCARBON
#define SystemSoundID as UInt32
#endif
toolbox fn AudioServicesCreateSystemSoundID ( CFURLRef inFileURL, SystemSoundID *outSystemSoundID ) = OSStatus
toolbox AudioServicesPlaySystemSound ( SystemSoundID inSystemSoundID )
toolbox fn AudioServicesDisposeSystemSoundID ( SystemSoundID inSystemSoundID ) = OSStatus
dim as CFURLRef soundURL(14)
soundURL(0) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Basso.aiff", NULL )
soundURL(1) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Blow.aiff", NULL )
soundURL(2) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Bottle.aiff", NULL )
soundURL(3) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Frog.aiff", NULL )
soundURL(4) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Funk.aiff", NULL )
soundURL(5) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Glass.aiff", NULL )
soundURL(6) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Hero.aiff", NULL )
soundURL(7) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Morse.aiff", NULL )
soundURL(8) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Ping.aiff", NULL )
soundURL(9) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Pop.aiff", NULL )
soundURL(10) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Purr.aiff", NULL )
soundURL(11) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Sosumi.aiff", NULL )
soundURL(12) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Submarine.aiff", NULL )
soundURL(13) = fn CFURLCreateWithString( _kCFAllocatorDefault, @"/System/Library/Sounds/Tink.aiff", NULL )
dim as long i
dim as SystemSoundID soundID
for i = 0 to 13
fn AudioServicesCreateSystemSoundID( soundURL(i), @soundID )
AudioServicesPlaySystemSound( soundID )
// Set latency between sounds here:
delay 200
CFRelease( soundURL(i) )
next
fn AudioServicesDisposeSystemSoundID( soundID )
RunApplicationEventLoop()