Tutorial #2: Playing background Music






Since a long time i try to find how to play music (*.mod or *ogg files) using GFA Basic 16. Unfortunately i never found DLL witch could do this. I try lot off possibilities without success.

A few years ago i found
mpxplay and i give me some hope because using Winexec i have succeeded in playing OGG music files !

But there was a big problem: I could not stop the music !

There was no code or command line instruction that can stop the music with mpxplay !

I stumbled a few days ago by doing a search on google on a message from a user who asks how kill a process in Visual Basic ...

Then I wondered if there was a Windows function that allow to stop a process , therefore to stop the player !

Here is the code:
(I try it on "Windows 7 x86" and on "Windows 7 x64" using "Microsoft Virtual PC 2007")

'
' ---> Play OGG files in GFA Windows 16
'

' ---------------------------
' DLL for calling Windows exe
' ---------------------------
' If someone know how to kill task using Kernel win 16, please explain me ! thanks !
'
DLL #1, "kernel"
DECL WORD WinExec( l, w )
ENDDLL

h% = WinExec(path$ + "/mpxplay/mpxplay.exe " + path$ + "/mod/music.ogg", SW_HIDE)

REPEAT
UNTIL MOUSEK=2

h% = WinExec(path$ + "/mpxplay/kill.bat",SW_HIDE)
FREEDLL 1


Oups, i don't speak about "kill.bat", it's just a small *.BAT file you can create with NOTEPAD. This file contain the following code:

TASKKILL /IM MPXPLAY.EXE

Then save it as "
KILL.BAT"

Of course it's not a nice way to code, but it works !!!