You need to log in to create posts and topics.
NSSound soundNamed:
1,678 Posts
#1 · July 22, 2010, 5:01 pm
Quote from Forum Archives on July 22, 2010, 5:01 pmPosted by: fblistserve <fblistserve@...>
My code allows the user to pick a sound file ( usually from /System/Library/Sounds but could be from anywhere ) and then uses the FSRef for the file to get a CFStringRef with the file name ( via FSGetCatalogInfo and CFStringCreateWithCharacters ) in it. That CFString is then fed into the PlaySound() wrapper ( nipped from Bernie ) shown below. PlaySound() works fine if the sound file ( usually an AIFF ) is in the application bundle but fails for sound files selected from system sound folders such as the one mentioned above. I’ve reduced the failure to soundNamed: not finding “Glass.aiff” in /System/Library/Sounds( the CFString fed to PlaySound contains “Glass.aiff” as expected ). Xcode docs for soundNamed: indicate it should find the sound:
~/Library/Sounds
/Library/Sounds
/Network/Library/Sounds
/System/Library/Sounds
Failing a mistake ( likely ), my thought is to convert the FSRef to a CFURLRef and feed to a wrapper function that can explicitly find the folder instead of relying on soundNamed:’s default search. Other ideas?'---------------BeginCFunctionvoid PlaySound( CFStringRef filename ){NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];NSSound *sound = [NSSound soundNamed:(NSString *)filename];[sound play];[localPool release];}EndCtoolbox PlaySound( CFStringRef filename )PlaySound( @"Glass.aiff" )RunApplicationEventLoop()'---------------Brian S
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Posted by: fblistserve <fblistserve@...>
My code allows the user to pick a sound file ( usually from /System/Library/Sounds but could be from anywhere ) and then uses the FSRef for the file to get a CFStringRef with the file name ( via FSGetCatalogInfo and CFStringCreateWithCharacters ) in it. That CFString is then fed into the PlaySound() wrapper ( nipped from Bernie ) shown below. PlaySound() works fine if the sound file ( usually an AIFF ) is in the application bundle but fails for sound files selected from system sound folders such as the one mentioned above. I’ve reduced the failure to soundNamed: not finding “Glass.aiff” in /System/Library/Sounds( the CFString fed to PlaySound contains “Glass.aiff” as expected ). Xcode docs for soundNamed: indicate it should find the sound:
-
~/Library/Sounds
-
/Library/Sounds
-
/Network/Library/Sounds
-
/System/Library/Sounds
Failing a mistake ( likely ), my thought is to convert the FSRef to a CFURLRef and feed to a wrapper function that can explicitly find the folder instead of relying on soundNamed:’s default search. Other ideas?
'---------------
BeginCFunction
void PlaySound( CFStringRef filename )
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
NSSound *sound = [NSSound soundNamed:(NSString *)filename];
[sound play];
[localPool release];
}
EndC
toolbox PlaySound( CFStringRef filename )
PlaySound( @"Glass.aiff" )
RunApplicationEventLoop()
'---------------
Brian S
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Click for thumbs down.0Click for thumbs up.0