Music Support
The music support is implemented using SDL_mixer.
Scrupp supports only one music file playing at a time. Because of that there is only one method for a music object: play. All the other music manipulating functions are independant from a special music object. They change whatever music file is playing at the moment.
Loading
- scrupp.addMusic(filename)
- Loads a music file with the given filename.
This can load WAV, MOD, XM, OGG and MP3.
Returns a music object.
Note: Only MP3 files with id3v1 tag are supported. If you try to load a file with id3v2 tag, the error message will say: Module format not recognized. To strip a possible id3v2 tag you can use the command id3convert from the id3lib:$ id3convert -s -2 <mp3 file>
Methods
- music:play([loops=0], [fade_in_time=0])
- Plays a music file loaded with scrupp.addMusic(). The optional parameter loops defines the number of times the music will be played. 0 means inifite looping and is the default. The optional parameter fade_in_time defines the number of milliseconds the music will fade in, the default is 0 ms.
Functions
- scrupp.setMusicVolume(volume)
- Sets the music volume to the specified value between 0 (mute) and 128 (maximum volume).
- scrupp.getMusicVolume()
- Returns the current music volume. This value is between 0 (mute) and 128 (maximum volume).
- scrupp.pauseMusic()
- Pauses the music playback. Paused music may be stopped with scrupp.stopMusic().
- scrupp.resumeMusic()
- Unpauses the music. This is safe to use on stopped, paused and playing music.
- scrupp.stopMusic([fade_out_time=0])
- Stop the playback of music. The optional paramter fade_out_time gives the number of milliseconds the music will fade out. It defaults to 0 ms.
- scrupp.rewindMusic()
- Rewinds the music to the start. This is safe to use on stopped, paused and playing music. This function only works for these streams: MOD, XM, OGG, MP3.
- scrupp.musicIsPlaying()
- Tells you if music is actively playing, or not.
Note: Does not check if the music has been paused, i.e. paused music returns true. Only stopped music returns false. - scrupp.musicIsPaused()
- Tells you if music is paused, or not.
Note: This state is only influenced by calls to scrupp.pauseMusic() and scrupp.resumeMusic().
Example
scrupp.init("Music Test", 600, 400, 32, false)
-- load some music
local music = scrupp.addMusic("path_to_music_file")
-- start music
music:play()
main = {
-- empty render function
render = function(dt)
end
}