View on GitHub

DSFML

dsfml.audio.music



class Music: dsfml.audio.soundstream.SoundStream;
Streamed music played from an audio file.

Musics are sounds that are streamed rather than completely loaded in memory.

This is especially useful for compressed musics that usually take hundreds of MB when they are uncompressed: by streaming it instead of loading it entirely, you avoid saturating the memory and have almost no loading delay.

Apart from that, a Music has almost the same features as the SoundBuffer / Sound pair: you can play/pause/stop it, request its parameters (channels, sample rate), change the way it is played (pitch, volume, 3D position, ...), etc.

As a sound stream, a music is played in its own thread in order not to block the rest of the program. This means that you can leave the music alone after calling play(), it will manage itself very well.

See Also:


http:
//sfml-dev.org/documentation/2.0/classsf_1_1Music.php#details

Authors:
Laurent Gomila, Jeremy DeHaan

bool openFromFile(string filename);
Open a music from an audio file.

This function doesn't start playing the music (call play() to do so).

Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Params:
string filename Path of the music file to open.

Returns:
True if loading succeeded, false if it failed.

bool openFromMemory(const(void)[] data);
Open a music from an audio file in memory.

This function doesn't start playing the music (call play() to do so).

Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Since the music is not loaded completely but rather streamed continuously, the data must remain available as long as the music is playing (ie. you can't deallocate it right after calling this function).

Params:
const(void)[] data The array of data

Returns:
True if loading succeeded, false if it failed.

bool openFromStream(InputStream stream);
Open a music from an audio file in memory.

This function doesn't start playing the music (call play() to do so).

Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Since the music is not loaded completely but rather streamed continuously, the stream must remain available as long as the music is playing (ie. you can't deallocate it right after calling this function).

Params:
InputStream stream Source stream to read from

Returns:
True if loading succeeded, false if it failed.

Time getDuration();
Get the total duration of the music.

Returns:
Music duration

protected bool onGetData(ref const(short)[] samples);
Request a new chunk of audio samples from the stream source.

This function fills the chunk from the next samples to read from the audio file.

Params:
const(short)[] samples Array of samples to fill

Returns:
True to continue playback, false to stop.

protected void onSeek(Time timeOffset);
Change the current playing position in the stream source.

Params:
Time timeOffset New playing position, from the beginning of the music

Implements SoundStream.