program HowToPlayMusic; uses SwinGame; procedure Main(); begin OpenAudio(); OpenGraphicsWindow('How To Play Music' ,320 ,240 ); LoadDefaultColors(); ClearScreen(ColorWhite ); LoadMusic('diving-turtle.mp3' ); PlayMusic('diving-turtle.mp3' ); DrawText('How To Play Music!!!' ,ColorRed ,40 ,120 ); RefreshScreen(); Delay(5000 ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Play Music
This how to explains how to play a music file in SwinGame. Only a single music file can be played at any one time, however it can be started and paused at any time.
Only a single music file can be played at one time (different to sound effects)
To play a music file in SwinGame, make sure it's located in the Resources/sounds subfolder. Call LoadMusic then PlayMusic to begin it playing back in the game loop. To ensure you have no memory leaks, close the audio file and release all resources at the end of your Main procedure.
The source code below highlights this procedure.
Under Windows a window need to be open in order for it to play audio
- Create a Slide Show with Music.