Audio Library

PreviousNext

Music

Music playback

There are two possibilities to play music with EiffelMedia Audio Library. It is recommended to play music using EM_MUSIC_PLAYER (see Players: Instant audio for further informations). The second solution is described in this document.

Loading music

If you want to load music, you need to inherit EM_SHARED_AUDIO_FACTORY. One can now access the singleton audio_factory, which allows you to load music using two different techniques. Music file may be one of the formats WAVE, MOD, MIDI, OGG or MP3 files.

Note: See MP3 support to enable MP3 support.

Most of the time one will use create_music_from_file, which takes the filename as an argument and also a command. This command is the empty string if you want to use the internal player, which should always be the default case. If you want to use any external player, the command should look like a complete command line expecting the filename as last argument.
Example: If you would call it like this: player -p file.ogg, the command would be "player -p ".

Another possibility to load music is to recreate a EM_MUSIC file from a pointer. Use create_music_from_pointer to handle this case.

Playing music

As music has its own single channel, one doesn't need to select a channel for playback.

To play your music file, simply call play, fade_in or fade_in_positioned. You may also pause, resume, stop and fade_out your music.

With music files, you have the possibility to set a position in track using set_position. But this does not work for the following filetypes:

Notes

As one perhaps already experienced, only create_music_from_file sets the filename of the newly created EM_MUSIC. For easier locating the music file in containers like a list, you should set the filename manually using set_filename.

Fading music is non-blocking. Be sure you don't interupt fading for example when quitting your application. You should always block fading using a loop halting when is_fading equals to False.