pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## pygame.mixer.music

The music module is tied closely to the pygame.mixer module. It is an optional module since it depends on the SDL_mixer library. You should not manually import the music library. Instead it is automatically included as a part of the mixer library. The default module path to music is pygame.mixer.music.
The difference between playback of music and playback of sounds is that the music object is not loaded and decoded all at once, instead the music data is streamed and decoded during playback. There can only be one music file loaded at a single time. Loading a new music file will replace any currently loaded music.
The music module has many of the same types of functions as the Sound objects. The main difference is only one music object can be loaded at a time, with the load() function. Music must be stored in an individual file on the system, it cannot be loaded from special file-like objects through python.

fadeout | - fadeout current music
get_busy | - query state of the music
get_endevent | - query the current music finished event
get_pos | - query music position
get_volume | - query music volume
load | - load current music
pause | - pause the playing music
play | - play the current loaded music
queue | - preload and queue a music file
rewind | - restarts music
set_endevent | - sets music finished event
set_volume | - set music volume
stop | - stop the playing music
unpause | - restarts the paused music

fadeout
`pygame.mixer.music.fadeout(millisec) -> None`

Fades out the current playing music and stops it over the given milliseconds.

get_busy
`pygame.mixer.music.get_busy() -> bool`

Returns true if music is currently playing

get_endevent
`pygame.mixer.music.get_endevent([eventid]) -> int`

When the music has finished playing, you can optionally have pygame place a user defined message on the event queue. If there is no callback event set, NOEVENT will be returned. Otherwise it will return the id of the current music finishe event.

get_pos
`pygame.mixer.music.get_pos() -> val`

Get the current (interpolated) time position of the music. Value is in ms, just like get_ticks().
The returned time is only tracking the amount of music played. It will not reflect the result of starting the music at an offset.

get_volume
`pygame.mixer.music.get_volume() -> val`

Get the current volume for the music. Value is between 0.0 and 1.0.

load
`pygame.mixer.music.load(filename) -> None`

Load a music object as the current music. The music only handles one music as the current. If music is currently playing, it will be stopped and replaced with the given one. Loading music only supports filenames, not file-like objects.

pause
`pygame.mixer.music.pause() -> None`

Temporarily stops the current music.

play
`pygame.mixer.music.play(loops=0, startpos=0.0) -> None`

Starts playing the current loaded music. This will restart the sound if it is playing. Loops controls how many extra time the sound will play, a negative loop will play indefinitely, it defaults to 0.
The starting position argument controls where in the music the song starts playing. The starting position is dependent on the format of music playing. MP3 and OGG use the position as time (in seconds). MOD music it is the pattern order number. Passing a startpos will raise a NotImplementedError if it cannot set the start position (or your version of SDL_mixer is too old)

queue
`pygame.mixer.music.queue(soundfile) -> None`

This will load a music file and queue it. A queued music file will begin as soon as the current music naturally ends. If the current music is ever stopped or changed, the queued song will be lost.

rewind
`pygame.mixer.music.rewind() -> None`

Restarts playback of the current music.

set_endevent
`pygame.mixer.music.set_endevent([eventid]) -> None`

When the music has finished playing, you can optionally have pygame place a user defined message on the event queue. If the eventid field is omittied or NOEVENT, no messages will be sent when the music finishes playing. Once the endevent is set, it will be called every time the music finished playing.

set_volume
`pygame.mixer.music.set_volume(val) -> None`

Sets the current volume for the music. Value is between 0.0 and 1.0.

stop
`pygame.mixer.music.stop() -> None`

Stops playback of the current music.

unpause
`pygame.mixer.music.unpause() -> None`

Restarts playback of the current music object when paused.