music - Pygame Documentation

pygame documentation | || Pygame Home || Help Contents || Reference Index || Camera || Cdrom || Color || Cursors || Display || Draw || Event || Examples || Font || Gfxdraw || Image || Joystick || Key || Locals || Mask || Midi || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Tests || Time || Transform

pygame.mixer.music

pygame module for controlling streamed audio

pygame.mixer.music.load - Load a music file for playback | Load a music file for playback
pygame.mixer.music.play - Start the playback of the music stream | Start the playback of the music stream
pygame.mixer.music.rewind - restart music | restart music
pygame.mixer.music.stop - stop the music playback | stop the music playback
pygame.mixer.music.pause - temporarily stop music playback | temporarily stop music playback
pygame.mixer.music.unpause - resume paused music | resume paused music
pygame.mixer.music.fadeout - stop music playback after fading out | stop music playback after fading out
pygame.mixer.music.set_volume - set the music volume | set the music volume
pygame.mixer.music.get_volume - get the music volume | get the music volume
pygame.mixer.music.get_busy - check if the music stream is playing | check if the music stream is playing
pygame.mixer.music.get_pos - get the music play time | get the music play time
pygame.mixer.music.queue - queue a music file to follow the current | queue a music file to follow the current
pygame.mixer.music.set_endevent - have the music send an event when playback stops | have the music send an event when playback stops
pygame.mixer.music.get_endevent - get the event a channel sends when playback stops | get the event a channel sends when playback stops

The music module is closely tied to `pygame.mixer`. Use the music module to control the playback of music in the sound mixer.

The difference between the music playback and regular Sound playback is that the music is streamed, and never actually loaded all at once. The mixer system only supports a single music stream at once.

Be aware that `MP3` support is limited. On some systems an unsupported format can crash the program, `e.g`. Debian Linux. Consider using `OGG` instead.

pygame.mixer.music.load

Load a music file for playback
`pygame.mixer.music.load(filename): return None`
`pygame.mixer.music.load(object): return None`

This will load a music filename/file object and prepare it for playback. If a music stream is already playing it will be stopped. This does not start the music playing.

pygame.mixer.music.play

Start the playback of the music stream
`pygame.mixer.music.play(loops=0, start=0.0): return None`

This will play the loaded music stream. If the music is already playing it will be restarted.

The loops argument controls the number of repeats a music will play. play(5) will cause the music to played once, then repeated five times, for a total of six. If the loops is -1 then the music will repeat indefinitely.

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

pygame.mixer.music.rewind

restart music
`pygame.mixer.music.rewind(): return None`

Resets playback of the current music to the beginning.

pygame.mixer.music.stop

stop the music playback
`pygame.mixer.music.stop(): return None`

Stops the music playback if it is currently playing.

pygame.mixer.music.pause

temporarily stop music playback
`pygame.mixer.music.pause(): return None`

Temporarily stop playback of the music stream. It can be resumed with the `pygame.mixer.music.unpause - resume paused music` function.

pygame.mixer.music.unpause

resume paused music
`pygame.mixer.music.unpause(): return None`

This will resume the playback of a music stream after it has been paused.

pygame.mixer.music.fadeout

stop music playback after fading out
`pygame.mixer.music.fadeout(time): return None`

This will stop the music playback after it has been faded out over the specified time (measured in milliseconds).

Note, that this function blocks until the music has faded out.

pygame.mixer.music.set_volume

set the music volume
`pygame.mixer.music.set_volume(value): return None`

Set the volume of the music playback. The value argument is between `0.0` and `1.0`. When new music is loaded the volume is reset.

pygame.mixer.music.get_volume

get the music volume
`pygame.mixer.music.get_volume(): return value`

Returns the current volume for the mixer. The value will be between `0.0` and `1.0`.

pygame.mixer.music.get_busy

check if the music stream is playing
`pygame.mixer.music.get_busy(): return bool`

Returns True when the music stream is actively playing. When the music is idle this returns False.

pygame.mixer.music.get_pos

get the music play time
`pygame.mixer.music.get_pos(): return time`

This gets the number of milliseconds that the music has been playing for. The returned time only represents how long the music has been playing; it does not take into account any starting position offsets.

pygame.mixer.music.queue

queue a music file to follow the current
`pygame.mixer.music.queue(filename): return 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.

The following example will play music by Bach six times, then play music by Mozart once:

        pygame.mixer.music.load('bach.ogg')
        pygame.mixer.music.play(5)        # Plays six times, not five!
        pygame.mixer.music.queue('mozart.ogg')

pygame.mixer.music.set_endevent

have the music send an event when playback stops
`pygame.mixer.music.set_endevent(): return None`
`pygame.mixer.music.set_endevent(type): return None`

This causes Pygame to signal (by means of the event queue) when the music is done playing. The argument determines the type of event that will be queued.

The event will be queued every time the music finishes, not just the first time. To stop the event from being queued, call this method with no argument.

pygame.mixer.music.get_endevent

get the event a channel sends when playback stops
`pygame.mixer.music.get_endevent(): return type`

Returns the event type to be sent every time the music finishes playback. If there is no endevent the function returns `pygame.NOEVENT`.