Contains sound mixer routines and objects.


  • pygame.mixer.quit() -> None
  • - unitializes the muxer
  • init([freq, [size, [stereo]]]) -> None
  • - initialize mixer module
  • pygame.mixer.get_init() -> bool
  • - query initialization for the mixer
  • pygame.mixer.pre_init([freq, [size, [stereo]]]) ->
  • - None
  • Sound.play([loops, [fadein], [maxtime]]]) ->
  • - Channel
  • Sound.get_num_channels() -> int
  • - number of channels with sound
  • Sound.get_busy() -> int
  • - Returns the number of channels this sound is actively playing on ;
  • Sound.get_channel(int) -> Channel
  • - Retrieves a channel index for this sound ;
  • Sound.fadeout(millisec) -> None
  • - fadeout all channels playing this sound
  • Sound.stop() -> None
  • - stop all channels playing this sound
  • Sound.set_volume(val) -> None
  • - change volume for sound
  • Sound.get_volume() -> val
  • - query volume for sound
  • Channel.play(Sound, [loops, [fadein], [maxtime]]])
  • - -> None
  • Channel.get_busy() -> bool
  • - query state of the channel
  • Channel.fadeout(millisec) -> None
  • - fade out the channel
  • Channel.stop() -> None
  • - stop playing on the channel
  • Channel.pause() -> None
  • - temporarily stop the channel
  • Channel.unpause() -> None
  • - restart a paused channel
  • Channel.set_volume(val) -> None
  • - set volume for channel
  • Channel.get_volume() -> val
  • - query the volume for the
  • pygame.mixer.get_num_channels() -> int
  • - query the number of channels
  • pygame.mixer.set_num_channels(int) -> None
  • - sets the number of available channels
  • pygame.mixer.set_reserved(int) -> None
  • - reserves first given channels
  • pygame.mixer.get_busy() -> int
  • - query busy channels
  • pygame.mixer.get_channel(int) -> Channel
  • - get channel object
  • pygame.mixer.find_channel([force]) -> Channel
  • -
  • pygame.mixer.fadeout(millisec) -> None
  • - fadeout all channels
  • pygame.mixer.stop() -> None
  • - stop all channels
  • pygame.mixer.pause() -> None
  • - pause all channels
  • pygame.mixer.unpause() -> None
  • - restart any pause channels
  • pygame.mixer.load(file) -> Sound
  • - load a new soundfile


    pygame.mixer.quit() -> None

    This will stop all playing sounds and uninitialize the mixer module


    init([freq, [size, [stereo]]]) -> None

    Initializes the mixer module. Usually no arguments will be needed, the defaults are 22050 frequency data in stereo with signed 16bit data. The size argument can be 8 or 16 for unsigned data, or -8 or -16 for signed data. On many platforms it is important that the display module is initialized before the audio. (that is, if the display will be initialized at all). You can easily use the pygame.init() function to cleanly initialize everything, but first use the pygame.mixer.pre_init() function to change the default values for this init().


    pygame.mixer.get_init() -> bool

    Returns true if the mixer module is initialized.


    pygame.mixer.pre_init([freq, [size, [stereo]]]) ->

    This routine is usefull when you want to customize the sound mixer playback modes. The values you pass will change the default values used by pygame.mixer.init(). This way you can still use the pygame automatic initialization to ensure everything happens in the right order, but set the desired mixer mode.


    Sound.play([loops, [fadein], [maxtime]]]) ->

    Starts playing a song on an available channel. If no channels are available, it will override the nonreserved channel that has been playing the longest. Loops controls how many extra times the sound will play, a negative loop will play indefinitely, it defaults to 0. Fadein will ramp the volume up over the given milliseconds, it defaults to 0. Maxtime is the number of total milliseconds that the sound will play. It defaults to forever (-1). Returns a channel object for the channel that is selected to play the sound.


    Sound.get_num_channels() -> int

    Returns the number of channels that have been using this sound. The channels may have already finished, but have not started playing any other sounds.


    Sound.get_busy() -> int


    Sound.get_channel(int) -> Channel


    Sound.fadeout(millisec) -> None

    Fade out all the playing channels playing this sound over the. All channels playing this sound will be stopped after the given milliseconds.


    Sound.stop() -> None

    This will instantly stop all channels playing this sound.


    Sound.set_volume(val) -> None

    Set the play volume for this sound. This will effect any channels currently playing this sound, along with all subsequent calls to play. The value is 0.0 to 1.0.


    Sound.get_volume() -> val

    Returns the current volume for this sound object. The value is 0.0 to 1.0.


    Channel.play(Sound, [loops, [fadein], [maxtime]]])

    Starts playing a given sound on this channel. If the channels is currently playing a different sound, it will be replaced/restarted with the given sound. Loops controls how many extra times the sound will play, a negative loop will play indefinitely, it defaults to 0. Fadein will ramp the volume up over the given milliseconds, it defaults to 0. Maxtime is the number of total milliseconds that the sound will play. It defaults to forever (-1).


    Channel.get_busy() -> bool

    Returns true when there is a sound actively playing on this channel.


    Channel.fadeout(millisec) -> None

    Fade out the playing sound and stops it over the given millisonds.


    Channel.stop() -> None

    Stops the sound that is playing on this channel.


    Channel.pause() -> None

    Stops the sound that is playing on this channel, but it can be resumed with a call to unpause()


    Channel.unpause() -> None

    Restarts a paused channel where it was paused.


    Channel.set_volume(val) -> None

    Sets the volume for the channel. The channel's volume level is mixed with the volume for the active sound object. The value is between 0.0 and 1.0.


    Channel.get_volume() -> val

    Returns the current volume for this sound object. The value is between 0.0 and 1.0.


    pygame.mixer.get_num_channels() -> int

    Gets the current number of channels available for the mixer. This value can be changed with set_num_channels(). This value defaults to 8 when the mixer is first initialized.


    pygame.mixer.set_num_channels(int) -> None

    Sets the current number of channels available for the mixer. This value defaults to 8 when the mixer is first initialized. If the value is decreased, sounds playing in channels above the new value will stop.


    pygame.mixer.set_reserved(int) -> None

    Reserves the first channels. Reserved channels won't be used when a sound is played without using a specific channel object.


    pygame.mixer.get_busy() -> int

    Returns the number of current active channels. This is not the total channels, but the number of channels that are currently playing sound.


    pygame.mixer.get_channel(int) -> Channel

    Get a channel object for the given channel. This number must be less that the current number of channels.


    pygame.mixer.find_channel([force]) -> Channel

    passed as a nonzero number, this will return the channel of the longest running sound. If not forced, and there are no available channels, returns None.


    pygame.mixer.fadeout(millisec) -> None

    Fade out all the playing channels over the given number of milliseconds.


    pygame.mixer.stop() -> None

    Stop the playback on all mixer channels.


    pygame.mixer.pause() -> None

    Temporarily stops playback on all the mixer channels.


    pygame.mixer.unpause() -> None

    Restarts playback of any paused channels.


    pygame.mixer.load(file) -> Sound

    Loads a new sound object from a WAV file. File can be a filename or a file-like object. The sound will be converted to match the current mode of the mixer.