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)


Level

Beginner

Read these first

About Audio

Details


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.





Source Code Widget

  • 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.
    Download Now"
  • #include 
    #include "SwinGame.h"
    int main() 
    {
    
        open_audio();
        open_graphics_window("How To Play Music" ,320 ,240 );
        load_default_colors();
        clear_screen(color_white );
        load_music("diving-turtle.mp3" );
        play_music("diving-turtle.mp3" );
        draw_text("How To Play Music!!!" ,color_red ,40 ,120 );
        refresh_screen();
        delay(5000 );
        close_audio();
        release_all_resources();
        return 0;
    }
    
    Download Now"
  • Source Code Coming Soon

  • Source Code Coming Soon

  • Source Code Coming Soon

Under Windows a window need to be open in order for it to play audio

Possibilities

  • Create a Slide Show with Music.