User Tools

Site Tools


Pausing and resuming MIDI playback

by Richard Russell, May 2006

BBC BASIC for Windows allows you to play a MIDI file using the *PLAY command. Whilst you can terminate playback before the song has finished by using the SOUND OFF statement, there is no built-in mechanism for pausing playback.

The program below makes it possible to pause and resume playback. For the purposes of the example a key-press is used, but the code can be adapted to control playback from any other source. For example in a game you may wish to pause the music whilst a high-score table is displayed.

        *PLAY C:\Windows\Media\Flourish.mid
        MCI_PLAY   = &806
        MCI_PAUSE  = &809
        PRINT "Press a key to pause and unpause..."
        pause% = FALSE
          IF GET THEN
            pause% = NOT pause%
            IF pause% THEN
              PROCmcicommand(@midi%, MCI_PAUSE, 0, 0)
              PRINT "Paused"
              PROCmcicommand(@midi%, MCI_PLAY, 0, 0)
              PRINT "Resumed"
        DEF PROCmcicommand(D%, C%, F%, S%)
        LOCAL K%, M%, O%, P%, T%
        DIM P% LOCAL 50
        [OPT 2
        .K% push S%:push F%:push C%:push D%:call "mciSendCommand"
        ret 16
        .M% cmp dword [esp+8],&500 : jz K%
        jmp [^O%]
        SWAP T%,@midi%
        SYS "GetWindowLong", @hwnd%, -4 TO O%
        SYS "SetWindowLong", @hwnd%, -4, M%
        SYS "SendMessage", @hwnd%, &500, 0, 0
        SYS "SetWindowLong", @hwnd%, -4, O%
        SYS "SendMessage", @hwnd%, 0, 0
        SWAP T%,@midi%

You may need to change the MIDI file specification if your PC doesn't have Flourish.mid in that location.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
pausing_20and_20resuming_20midi_20playback.txt · Last modified: 2018/04/15 13:34 by richardrussell