class

Tryst::SDL::Music

Inherits Tryst::SDL::AudioSource < Reference < Object

A longer piece of audio - a background track - streamed from disk rather than decoded up front, and played on one Track it owns.

music = Tryst::SDL::Music.new("background.mp3")
music.gain = 0.4
music.play # loops forever by default
music.fade_out(1500)

Nothing here limits playback to one music at a time - a Music is an ordinary audio source on an ordinary track, so several can run at once. Keeping to one is the application's choice, not a rule.

Constructors

new(path : String, mixer : Mixer = Mixer.default)
Source

Instance methods

destroy

Stops playback, frees the track, then frees the decoded audio.

Source
fade_out(ms : Int32) : self

Fades out over ms and stops. The same thing as stop(ms), named for how it reads at the call site.

Source
gain

Gain for this music alone, multiplied with the mixer's: 1.0 unchanged, 0.0 silent.

Source
gain=(value : Float32 | Float64) : Float32
Source
loops_remaining

Passes still to come, counting down; -1 while looping forever.

Source
loops_remaining=(count : Int32) : Int32

Setting this to 0 is how an endless music is brought to a graceful end: the current pass finishes rather than being cut off mid-sample the way #stop would.

Source
pause
Source
paused?
Source
play(loops : Int32 = -1, fade_ms : Int32 = 0) : self

Starts, or restarts, playback. loops counts EXTRA passes, so the default of -1 repeats forever and 0 plays through once.

Source
playing?

Playing, paused and stopped are mutually exclusive, so a PAUSED MUSIC IS NOT PLAYING. To ask "has this been started at all", use !stopped?.

Source
position_ms

How far in it has played, or nil if the input cannot say - the number a progress bar wants.

Source
position_ms=(ms : Int) : Int

Seeks. Needs a seekable input, which a streamed file normally is.

Source
remaining_ms

How much of the current pass is left, or nil if unknown. Looping does not extend it - it is the remainder of this pass.

Source
resume
Source
stop(fade_ms : Int32 = 0) : self

Halts playback, fading to silence first when asked.

Source
stopped?

Neither playing nor paused: never started, finished, or stopped.

Source
track

The track this music plays on, for the things Track can do that Music does not wrap - starting part-way in, say.

Source