PDA

View Full Version : sound_play replacement?



sandyrepope
22-09-2007, 21:42
In the help file it says that sound_play has been deleted.

Has there been anything added to replace sound_play?

I hoped that there would be a simple way to play short .wav files from my scripts. All I want to do is play a simple sound effect like the tada.wav. So far I haven't been able to figure out how to do simple sound effects on my own.

I've been looking at the tbass module but I'm afraid I don't understand how to use it.

Is tbass the only way to get sound effects in thinbasic?

Thanks
Sandy

ErosOlmi
22-09-2007, 22:44
Yes, there is a simple way just using windows API. See following script.
Should work fine in all systems

Ciao
Eros



Declare Function PlaySound Lib "winmm" Alias "PlaySoundA" _
( ByVal szName As String, _
ByVal hModule As Long, _
ByVal dwFlags As Long) As Long

dim sFile as string = "chimes.wav"

%SND_SYNC = &H0
%SND_ASYNC = &H1

PlaySound(sFile, 0, %SND_SYNC)

sandyrepope
23-09-2007, 01:48
ErosOlmi, Thanks for the reply and script. I appreciate it.

I have a question. Won't sFile require a full path?

Thanks
Sandy

Petr Schreiber
23-09-2007, 08:30
Hi Sandy,

it is always good to specify full path, but MSDN documentation does not say anything about it.

Still, first parameter has quite hybrid meaning:


A string that specifies the sound to play. The maximum length, including the null terminator, is 256 characters. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.

Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename.



Bye,
Petr

ErosOlmi
23-09-2007, 09:40
ErosOlmi, Thanks for the reply and script. I appreciate it.

I have a question. Won't sFile require a full path?

Thanks
Sandy


Yes Sandy you are right. To avoid problems it is always better to indicate full path.
So something like:



dim sFile as string = APP_SourcePath & "chimes.wav" '---If wav file is in then same dir of the script


would have been better.

Regarding NULL terminator, all thinBasic dynamic strings are automatically always NULL terminated by the OLE32 engine. So do not worry about that in MSDN documentation.

Thanks
Eros

sandyrepope
23-09-2007, 17:43
The reason I was asking was that I was thinking that if the sound effects are kept in a /sound folder the full path would be needed. I like the idea of keeping the resources all in their own folders.

Thanks
Sandy

ErosOlmi
23-09-2007, 19:11
Yes Sandy, it is the right choice.

In any case my original example was just to show how to call PlaySound API. The rest is programmer responsability ;)

Ciao
Eros