[futurebasic] Playing sounds with SystemSoundActionIDs

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2007 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Wed, 5 Dec 2007 10:00:05 -0500
Here is some code I have been playing with that approaches playing  
sounds from a different direction. To be fully workable the toolbox  
functions SystemSoundSetCompletionRoutine and  
SystemSoundRemoveCompletionRoutine would need to
be implemented to detect when the sound had completed playing and was  
ready to be disposed. Those functions are found in SystemSound.h. For  
demo purposes here I just use an FB delay since, to be frank, I  
haven't figured out how to use the aforementioned functions.

Ken

/*

Play Sound

    Demo based on SystemSoundActionIDs
    found in the SystemSound.h

    Ken Shmidheiser
    Dec. 5, 2007

*/

include "Tlbx MoreFilesX.incl"

// Defined in SystemSound.h
#define SystemSoundActionID as UInt32

toolbox fn SystemSoundGetActionID( const FSRef *userFile,  
SystemSoundActionID *outAction ) = OSStatus
toolbox AlertSoundPlayCustomSound( SystemSoundActionID inAction )
toolbox SystemSoundRemoveActionID( SystemSoundActionID inAction )

begin globals
dim as SystemSoundActionID gSystemSound
end globals

local fn CreateSoundActionID( pathToSound as str255 )
dim as FSRef     soundFileRef
dim as str255   filepath
dim as OSStatus  err

filepath = pathToSound + chr$( 0 )
err = fn FSPathMakeRef( filepath[1], @soundFileRef, #0 )
long if ( err == _noErr )
err = fn SystemSoundGetActionID( @soundFileRef, @gSystemSound )
end if

end fn = err

local fn PlaySoundActionID
call AlertSoundPlayCustomSound( gSystemSound )
end fn

local fn CleanUpSoundActionID
call SystemSoundRemoveActionID( gSystemSound )
end fn

window 1

dim as str255 soundPath(15)
dim as long i

/*
System sound paths are supplied, but code
will play

*/
soundPath(1)  = "/System/Library/Sounds/Basso.aiff"
soundPath(2)  = "/System/Library/Sounds/Bottle.aiff"
soundPath(3)  = "/System/Library/Sounds/Funk.aiff"
soundPath(4)  = "/System/Library/Sounds/Hero.aiff"
soundPath(5)  = "/System/Library/Sounds/Ping.aiff"
soundPath(6)  = "/System/Library/Sounds/Purr.aiff"
soundPath(7)  = "/System/Library/Sounds/Submarine.aiff"
soundPath(8)  = "/System/Library/Sounds/Blow.aiff"
soundPath(9)  = "/System/Library/Sounds/Frog.aiff"
soundPath(10) = "/System/Library/Sounds/Glass.aiff"
soundPath(11) = "/System/Library/Sounds/Morse.aiff"
soundPath(12) = "/System/Library/Sounds/Pop.aiff"
soundPath(13) = "/System/Library/Sounds/Sosumi.aiff"
soundPath(14) = "/System/Library/Sounds/Tink.aiff"
soundPath(14) = "/System/Library/Sounds/Tink.aiff"

for i = 1 to 14
print mid$( soundPath(i), 24 )
fn CreateSoundActionID( soundPath(i) )
fn PlaySoundActionID
/*
The delay here is for demo purposes. For an actual
application, SystemSoundSetCompletionRoutine and
SystemSoundRemoveCompletionRoutine would need to
be implemented to detect when the sound was completed
before sending it to be disposed.
*/
delay 1000
fn CleanUpSoundActionID
next i

print:print "Done"

do
handleevents
until gFBQuit
end