Le 1 sept. 06 à 02:40 Matin, Brian Heibert a écrit:
How do I play a sound resource in RB?
I got aresource file and in it
is a resource of type snd id 28 name Welcome
something like that:
Add a property to your window (example: MySound as sound).
This property will hold the sound, so you can control it while it is
playing (stop it, change its volume, etc).
dim f as FolderItem
dim r as ResourceFork
f=getfolderitem("").child("MyFile") 'Looks for a file "MyFile" in the
same folder as your application; you can locate it somehow else.
if f<>nil then 'f is valid
r=f.OpenResourceFork 'Opens the file's resource fork
if r<>nil then 'if r is nil, your file doesn't have resources. We
only continue if the file has a resource fork (else, we get an error:
nilobjectexception).
MySound=r.GetSound(128) 'r.GetSound: retrieves a sound in the
resource. Since a sound is a "snd " resource, you don't have to
specify a type (RB looks automatically for "snd "). The name is also
not useful (a type and an ID is the required to find a resource). 128
is, as you can guess, the resource ID
if MySound<>nil then 'if MySound is nil, the sound was not able to be
loaded (bad sound format (error -206) or resource does not exist
(error -192), etc.). If MySound is not nil, we play it
MySound.Play
end If
r.Close 'The resource fork must be closed to release the file.
end if
end if_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>