<html> <title>music - Pygame Documentation</title> <body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111> <table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'> <tr> <td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td> <td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center> || <a href=http://www.pygame.org>Pygame Home</a> || <a href=../index.html>Help Contents</a> || <a href=index.html>Reference Index</a> || <br> <br> <a href="camera.html">Camera</a> || <a href="cdrom.html">Cdrom</a> || <a href="color.html">Color</a> || <a href="cursors.html">Cursors</a> || <a href="display.html">Display</a> || <a href="draw.html">Draw</a> || <a href="event.html">Event</a> || <a href="examples.html">Examples</a> || <a href="font.html">Font</a> || <a href="gfxdraw.html">Gfxdraw</a> || <a href="image.html">Image</a> || <a href="joystick.html">Joystick</a> || <a href="key.html">Key</a> || <a href="locals.html">Locals</a> || <a href="mask.html">Mask</a> || <a href="midi.html">Midi</a> || <a href="mixer.html">Mixer</a> || <a href="mouse.html">Mouse</a> || <a href="movie.html">Movie</a> || <a href="music.html">Music</a> || <a href="overlay.html">Overlay</a> || <a href="pixelarray.html">Pixelarray</a> || <a href="pygame.html">Pygame</a> || <a href="rect.html">Rect</a> || <a href="scrap.html">Scrap</a> || <a href="sndarray.html">Sndarray</a> || <a href="sprite.html">Sprite</a> || <a href="surface.html">Surface</a> || <a href="surfarray.html">Surfarray</a> || <a href="tests.html">Tests</a> || <a href="time.html">Time</a> || <a href="transform.html">Transform</a> </td></tr></table> <br> <a name="pygame.mixer.music"> <big><b>pygame.mixer.music</big></b><br><ul> <i>pygame module for controlling streamed audio</i><br> <ul><small><table> <tr><td><a href="music.html#pygame.mixer.music.load">pygame.mixer.music.load</a> - <font size=-1>Load a music file for playback</font></td><td>Load a music file for playback</td></tr> <tr><td><a href="music.html#pygame.mixer.music.play">pygame.mixer.music.play</a> - <font size=-1>Start the playback of the music stream</font></td><td>Start the playback of the music stream</td></tr> <tr><td><a href="music.html#pygame.mixer.music.rewind">pygame.mixer.music.rewind</a> - <font size=-1>restart music</font></td><td>restart music</td></tr> <tr><td><a href="music.html#pygame.mixer.music.stop">pygame.mixer.music.stop</a> - <font size=-1>stop the music playback</font></td><td>stop the music playback</td></tr> <tr><td><a href="music.html#pygame.mixer.music.pause">pygame.mixer.music.pause</a> - <font size=-1>temporarily stop music playback</font></td><td>temporarily stop music playback</td></tr> <tr><td><a href="music.html#pygame.mixer.music.unpause">pygame.mixer.music.unpause</a> - <font size=-1>resume paused music</font></td><td>resume paused music</td></tr> <tr><td><a href="music.html#pygame.mixer.music.fadeout">pygame.mixer.music.fadeout</a> - <font size=-1>stop music playback after fading out</font></td><td>stop music playback after fading out</td></tr> <tr><td><a href="music.html#pygame.mixer.music.set_volume">pygame.mixer.music.set_volume</a> - <font size=-1>set the music volume</font></td><td>set the music volume</td></tr> <tr><td><a href="music.html#pygame.mixer.music.get_volume">pygame.mixer.music.get_volume</a> - <font size=-1>get the music volume</font></td><td>get the music volume</td></tr> <tr><td><a href="music.html#pygame.mixer.music.get_busy">pygame.mixer.music.get_busy</a> - <font size=-1>check if the music stream is playing</font></td><td>check if the music stream is playing</td></tr> <tr><td><a href="music.html#pygame.mixer.music.get_pos">pygame.mixer.music.get_pos</a> - <font size=-1>get the music play time</font></td><td>get the music play time</td></tr> <tr><td><a href="music.html#pygame.mixer.music.queue">pygame.mixer.music.queue</a> - <font size=-1>queue a music file to follow the current</font></td><td>queue a music file to follow the current</td></tr> <tr><td><a href="music.html#pygame.mixer.music.set_endevent">pygame.mixer.music.set_endevent</a> - <font size=-1>have the music send an event when playback stops</font></td><td>have the music send an event when playback stops</td></tr> <tr><td><a href="music.html#pygame.mixer.music.get_endevent">pygame.mixer.music.get_endevent</a> - <font size=-1>get the event a channel sends when playback stops</font></td><td>get the event a channel sends when playback stops</td></tr> </table></small></ul> <p>The music module is closely tied to <tt>pygame.mixer</tt>. Use the music module to control the playback of music in the sound mixer. </p> <p>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. </p> <p>Be aware that <tt>MP3</tt> support is limited. On some systems an unsupported format can crash the program, <tt>e.g</tt>. Debian Linux. Consider using <tt>OGG</tt> instead. </p> <!--COMMENTS:pygame.mixer.music--> <br> <a name="pygame.mixer.music.load"> <big><b>pygame.mixer.music.load</big></b><br><ul> <i>Load a music file for playback</i><br> <tt>pygame.mixer.music.load(filename): return None</tt><br> <tt>pygame.mixer.music.load(object): return None</tt><br> <p>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. </p> <!--COMMENTS:pygame.mixer.music.load--> <br> <br></ul> <a name="pygame.mixer.music.play"> <big><b>pygame.mixer.music.play</big></b><br><ul> <i>Start the playback of the music stream</i><br> <tt>pygame.mixer.music.play(loops=0, start=0.0): return None</tt><br> <p>This will play the loaded music stream. If the music is already playing it will be restarted. </p> <p>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. </p> <p>The starting position argument controls where in the music the song starts playing. The starting position is dependent on the format of music playing. <tt>MP3</tt> and <tt>OGG</tt> use the position as time (in seconds). <tt>MOD</tt> music it is the pattern order number. Passing a startpos will raise a NotImplementedError if it cannot set the start position </p> <!--COMMENTS:pygame.mixer.music.play--> <br> <br></ul> <a name="pygame.mixer.music.rewind"> <big><b>pygame.mixer.music.rewind</big></b><br><ul> <i>restart music</i><br> <tt>pygame.mixer.music.rewind(): return None</tt><br> <p>Resets playback of the current music to the beginning. </p> <!--COMMENTS:pygame.mixer.music.rewind--> <br> <br></ul> <a name="pygame.mixer.music.stop"> <big><b>pygame.mixer.music.stop</big></b><br><ul> <i>stop the music playback</i><br> <tt>pygame.mixer.music.stop(): return None</tt><br> <p>Stops the music playback if it is currently playing. </p> <!--COMMENTS:pygame.mixer.music.stop--> <br> <br></ul> <a name="pygame.mixer.music.pause"> <big><b>pygame.mixer.music.pause</big></b><br><ul> <i>temporarily stop music playback</i><br> <tt>pygame.mixer.music.pause(): return None</tt><br> <p>Temporarily stop playback of the music stream. It can be resumed with the <tt><a href="music.html#pygame.mixer.music.unpause">pygame.mixer.music.unpause</a> - <font size=-1>resume paused music</font></tt> function. </p> <!--COMMENTS:pygame.mixer.music.pause--> <br> <br></ul> <a name="pygame.mixer.music.unpause"> <big><b>pygame.mixer.music.unpause</big></b><br><ul> <i>resume paused music</i><br> <tt>pygame.mixer.music.unpause(): return None</tt><br> <p>This will resume the playback of a music stream after it has been paused. </p> <!--COMMENTS:pygame.mixer.music.unpause--> <br> <br></ul> <a name="pygame.mixer.music.fadeout"> <big><b>pygame.mixer.music.fadeout</big></b><br><ul> <i>stop music playback after fading out</i><br> <tt>pygame.mixer.music.fadeout(time): return None</tt><br> <p>This will stop the music playback after it has been faded out over the specified time (measured in milliseconds). </p> <p>Note, that this function blocks until the music has faded out. </p> <!--COMMENTS:pygame.mixer.music.fadeout--> <br> <br></ul> <a name="pygame.mixer.music.set_volume"> <big><b>pygame.mixer.music.set_volume</big></b><br><ul> <i>set the music volume</i><br> <tt>pygame.mixer.music.set_volume(value): return None</tt><br> <p>Set the volume of the music playback. The value argument is between <tt>0.0</tt> and <tt>1.0</tt>. When new music is loaded the volume is reset. </p> <!--COMMENTS:pygame.mixer.music.set_volume--> <br> <br></ul> <a name="pygame.mixer.music.get_volume"> <big><b>pygame.mixer.music.get_volume</big></b><br><ul> <i>get the music volume</i><br> <tt>pygame.mixer.music.get_volume(): return value</tt><br> <p>Returns the current volume for the mixer. The value will be between <tt>0.0</tt> and <tt>1.0</tt>. </p> <!--COMMENTS:pygame.mixer.music.get_volume--> <br> <br></ul> <a name="pygame.mixer.music.get_busy"> <big><b>pygame.mixer.music.get_busy</big></b><br><ul> <i>check if the music stream is playing</i><br> <tt>pygame.mixer.music.get_busy(): return bool</tt><br> <p>Returns True when the music stream is actively playing. When the music is idle this returns False. </p> <!--COMMENTS:pygame.mixer.music.get_busy--> <br> <br></ul> <a name="pygame.mixer.music.get_pos"> <big><b>pygame.mixer.music.get_pos</big></b><br><ul> <i>get the music play time</i><br> <tt>pygame.mixer.music.get_pos(): return time</tt><br> <p>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. </p> <!--COMMENTS:pygame.mixer.music.get_pos--> <br> <br></ul> <a name="pygame.mixer.music.queue"> <big><b>pygame.mixer.music.queue</big></b><br><ul> <i>queue a music file to follow the current</i><br> <tt>pygame.mixer.music.queue(filename): return None</tt><br> <p>This will load a music file and queue it. <tt>A</tt> 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. </p> <p>The following example will play music by Bach six times, then play music by Mozart once: </p> <pre> pygame.mixer.music.load('bach.ogg') pygame.mixer.music.play(5) # Plays six times, not five! pygame.mixer.music.queue('mozart.ogg') </pre> <!--COMMENTS:pygame.mixer.music.queue--> <br> <br></ul> <a name="pygame.mixer.music.set_endevent"> <big><b>pygame.mixer.music.set_endevent</big></b><br><ul> <i>have the music send an event when playback stops</i><br> <tt>pygame.mixer.music.set_endevent(): return None</tt><br> <tt>pygame.mixer.music.set_endevent(type): return None</tt><br> <p>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. </p> <p>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. </p> <!--COMMENTS:pygame.mixer.music.set_endevent--> <br> <br></ul> <a name="pygame.mixer.music.get_endevent"> <big><b>pygame.mixer.music.get_endevent</big></b><br><ul> <i>get the event a channel sends when playback stops</i><br> <tt>pygame.mixer.music.get_endevent(): return type</tt><br> <p>Returns the event type to be sent every time the music finishes playback. If there is no endevent the function returns <tt>pygame.NOEVENT</tt>. </p> <!--COMMENTS:pygame.mixer.music.get_endevent--> <br> <br></ul> <br></ul> </body></html>