Hello, if I use PlaySound() in End of Thread, then Sound not played (or played shortly) because thread exiting (quit). Can I fix it without API use, only with PB?
Your thread must indeed wait until the sound has time to play. But how long is that? For wav files, you can use the provided proc. It can be tweaked for other formats. What I'd do is use it to find the playtime of each sound file and put a constant at the top of your code for each, something like #EXPLOSION_1_MS = 1669 and then Delay(#EXPLOSION_1_MS) at the end of your thread procedure. This way you can use IncludeBinary and CatchSound(). But if you don't mind loading the sound from HD, RASHAD's solution is fine too.
Another possibility is to use MCI (a relict from old windows versions), which works fine with different file formats...
There are a couple of commands available, after you have loaded a song... mciSendString_("open " + #DQUOTE$+ActSongFile+#DQUOTE$ + " type mpegvideo alias song3", 0, 0, 0)
...you can start playing... mciSendString_("play song3", 0, 0, 0)
...get the music length... Dummy.s=Space(#MAX_PATH)
mciSendString_("status song3 length",Dummy,#MAX_PATH,0)
ActLength=Val(Dummy)
...and check if the song has reached the end position... Dummy.s=Space(#MAX_PATH)
mciSendString_("status song3 position",Dummy,#MAX_PATH,0)
SongPosition=Val(Dummy)
If ActLength
If SongPosition=ActLength
Finished!!!
EndIf
EndIf
It seems that PlaySound() implements asynchronously. So you can get the total duration of the sound in advance of playing, then call Sleep() and set the param to the duration you have just got. And then... all is OK!
As for the way of getting the duration of the sound, you can refer to relative documents according to the sound format.