Blitz3D+ Command Reference

PauseChannel channel

Parameters

channel - channel handle returned by PlaySound or PlayMusic

Description

Holds a playing channel where it is, ready to carry on later.

The playback keeps its position, so ResumeChannel picks up exactly where it left off rather than starting over. That is the difference from StopChannel, which ends the channel for good.

The obvious use is a pause menu: walk your list of active channels, pause them all, and resume them when play continues, so the music does not restart from the top every time the player checks the map. It is equally handy for ducking a long ambience while a cutscene or voice line runs.

It is a Channel command and needs the handle you kept when you started the sound. Keeping a small array of the channels you care about is the usual way to pause them as a group.

Worth knowing: a paused channel still reports True from ChannelPlaying, because it is holding its place rather than finishing. If your code treats that as "sound is audible" it will draw the wrong conclusion - track the paused state yourself. Pausing an already-paused or already-finished channel does nothing.

See also: ResumeChannel, StopChannel, ChannelPlaying, PlaySound, PlayMusic.

Example

; PauseChannel Example
; --------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; A short tone looped endlessly gives us a steady engine hum
snd=LoadSound("media/beep.wav")
LoopSound snd
channel=PlaySound(snd)

paused=0
angle#=0

While Not KeyDown(1)

    ; P pauses the channel: playback freezes but the channel survives
    If KeyHit(25) And paused=0 Then
        PauseChannel channel
        paused=1
    End If

    ; R resumes it exactly where it left off (see ResumeChannel)
    If KeyHit(19) And paused=1 Then
        ResumeChannel channel
        paused=0
    End If

    ; The fan only spins while the engine hum is running
    If paused=0 Then angle=angle+4

    Cls

    Color 100,100,100
    Oval 250,170,140,140,False
    Color 255,255,255
    Line 320,240,320+Cos(angle)*60,240+Sin(angle)*60
    Line 320,240,320-Cos(angle)*60,240-Sin(angle)*60

    If paused Then
        Color 255,180,80
        Text 320,340,"PAUSED - PauseChannel channel",True
    Else
        Color 80,255,80
        Text 320,340,"RUNNING",True
    End If

    Color 255,255,255
    Text 0,0,"P: pause   R: resume   Esc: exit"

    Flip

Wend

StopChannel channel

End

Index