[futurebasic] Re: SndStartFilePlay

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2003 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Thu, 19 Jun 2003 08:56:33 -0400
In this thread concerning playing sounds with QuickTime in Carbon, Keiji wrote:

>Hi Alain,
>Thank you very much; however, what I was looking
>for was a means to play a snd resource by giving
>a snd resource ID in a file just like we used to
>be able with SndStartFilePlay under OS 8/9. Any
>suggestions would be appreciated.


Keiji,

This should give you back the ability to play _"snd " resources in 
Carbon and OS X.

Let me know if it works for you.

Best,

Ken


p.s. Watch for e-mail line breaks and lost constant underscores on 
Associate server.

/*

    Playing Sounds from _"snd " resources in Carbon and OS X
    Demo by Ken Shmidheiser
    Somerset, KY
    6-19-03

*/

'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                      Debugger : Off
'               DIM'd Vars Only : On
'              No Re-DIM'd Vars : On
'                    CALL Req'd : Off
'                 Register Vars : On
'                MacsBug Labels : On
'           Ary Bounds Checking : On
'                     QB Labels : Off
'                 Optimize STR# : On
'         Make Line Start Table : Off
'                 Show Warnings : On
'~'B

resources "mySound.rsrc"

local fn PlaySndResource( mySndResID as long )
dim as handle mySndHandle
dim as OSErr  err

_kAsync = _true   // for asynchronous play
_kSync  = _false  // for synchronous play

mySndHandle = fn GetResource( _"snd ", mySndResID )
err = fn ResError // remember any error
long if mySndHandle != _nil// check for a valid handle
HLock( mySndHandle ) // lock the sound data
err = fn SndPlay( _nil, mySndHandle, _kSync )
HUnlock( mySndHandle ) // unlock the sound data
ReleaseResource( mySndHandle )// release handle from memory
end if

end fn = err

dim as OSErr sndErr

window 1
print "Playing your sound"

sndErr = fn PlaySndResource( 128 )

long if sndErr = _noErr
xelse
select case sndErr
case -201
print "Insufficient hardware available"
case -204
print "Problem loading the resource"
case -205
print "Channel is corrupt or unusable"
case -206
print "Insufficient hardware available"
case else
print "Unknown error"
end select
end if

do
handleevents
until 0
end