|
pygame.mixer.init | initialize the mixer module |
pygame.mixer.pre_init | preset the mixer init arguments |
pygame.mixer.quit | uninitialize the mixer |
pygame.mixer.get_init | test if the mixer is initialized |
pygame.mixer.stop | stop playback of all sound channels |
pygame.mixer.pause | temporarily stop playback of all sound channels |
pygame.mixer.unpause | resume pause playback of sound channels |
pygame.mixer.fadeout | fade out the volume on all sounds before stopping |
pygame.mixer.set_num_channels | set the total number of playback channels |
pygame.mixer.get_num_channels | get the total number of playback channels |
pygame.mixer.set_reserved | reserve channels from being automatically used |
pygame.mixer.find_channel | find an unused channel |
pygame.mixer.get_busy | test if any sound is being mixed |
pygame.mixer.Sound | Create a new Sound object from a file |
pygame.mixer.Channel | Create a Channel object for controlling playback |
This module contains classes for loading Sound objects and controlling playback. The mixer module is optional and depends on SDL_mixer. Your program should test that pygame.mixer is available and intialized before using it.
The mixer module has a limited number of channels for playback of sounds. Usually programs tell pygame to start playing audio and it selects an available channel automatically. The default is 8 simultaneous channels, but complex programs can get more precise control over the number of channels and their use.
All sound playback is mixed in background threads. When you begin to play a Sound object, it will return immediately while the sound continues to play. A single Sound object can also be actively played back multiple times.
The mixer also has a special streaming channel. This is for music playback and is accessed through the pygame.mixer.music module.
The mixer module must be initialized like other pygame modules, but it has some extra conditions. The pygame.mixer.init function takes several optional arguments to control the playback rate and sample size. Pygame will default to reasonable values, but pygame cannot perform Sound resampling, so the mixer should be initialized to match the values of your audio resources.
Initialize the mixer module for Sound loading and playback. The default arguments can be overridden to provide specific audio mixing. The size argument represents how many bits are used for each audio sample. If the value is negative then signed sample values will be used. Positive values mean unsigned audio samples will be used. If the stereo argument is false the mixer will use mono sound.
The buffer argument controls the number of internal samples used in the sound mixer. The default value should work for most cases. It can be lowered to reduce latency, but sound dropout may occur. It can be raised to larger values to ensure playback never skips, but it will impose latency on sound playback. The buffer size must be a power of two.
Some platforms require the pygame.mixer module to be required after the display modules have initialized. The top level pygame.init takes care of this automatically, but cannot pass any arguments to the mixer init. To solve this, mixer has a function pygame.mixer.pre_init to set the proper defaults before the toplevel init is used.
It is safe to call this more than once, but after the mixer is initialized you cannot change the playback arguments without first calling pygame.mixer.quit.
Any nonzero arguments change the default values used when the real pygame.mixer.init is called. The best way to set custom mixer playback values is to call pygame.mixer.pre_init before calling the top level pygame.init.
This will uninitialize pygame.mixer. All playback will stop and any loaded Sound objects may not be compatable with the mixer if it is reinitialized later.
If the mixer is initialized, this returns the playback arguments it is using. If the mixer has not been initialized this returns None
This will stop all playback of all active mixer channels.
This will temporarily stop all playback on the active mixer channels. The playback can later be resumed with pygame.mixer.unpause
This will resume all active sound channels after they have been paused.
This will fade out the volume on all active channels over the time argument in milliseconds. After the sound is muted the playback will stop.
Sets the number of available channels for the mixer. The default value is 8. The value can be increased or decreased. If the value is decreased, sounds playing on the truncated channels are stopped.
Returns the number of currently active playback channels.
The mixer can reserve any number of channels that will not be automatically selected for playback by Sounds. If sounds are currently playing on the reserved channels they will not be stopped.
This allows the application to reserve a specific number of channels for important sounds that must not be dropped or have a guaranteed channel to play on.
This will find and return an inactive Channel object. If there are no inactive Channels this function will return None. If there are no inactive channels and the force argument is True, this will find the Channel with the longest running Sound and return it.
If the mixer has reserved channels from pygame.mixer.set_reserved then those channels will not be returned here.
Returns True if the mixer is busy mixing any channels. If the mixer is idle then this return False.
Sound.play | begin sound playback |
Sound.stop | stop sound playback |
Sound.fadeout | stop sound playback after fading out |
Sound.set_volume | set the playback volume for this Sound |
Sound.get_volume | get the playback volume |
Sound.get_num_channels | count how many times this Sound is playing |
Sound.get_length | get the length of the Sound |
Load a new sound buffer from a filename or from a python file object. Limited resampling will be performed to help the sample match the initialize arguments for the mixer.
The Sound object represents actual sound sample data. Methods that change the state of the Sound object will the all instances of the Sound playback.
The Sound can be loaded from an OGG audio file or from an uncompressed WAV.
Begin playback of the Sound on an available Channel. This will forcibly select a Channel, so playback may cut off a currently playing sound if necessary.
The loops argument controls how many times the sample will be played. If loops is set to -1 the Sound will loop indefinitely. The maxtime argument can be used to stop playback after a given number of milliseconds.
This returns the Channel object for the channel that was selected.
This will stop the playback of this Sound on any active Channels.
This will stop playback of the sound after fading it out over the time argument in milliseconds. The Sound will fade and stop on all actively playing channels.
This will set the playback volume for this Sound. This will immediately affect the Sound if it is playing. It will also affect any future playback of this Sound. The argument is a value from 0.0 to 1.0.
Return a value from 0.0 to 1.0 representing the volume for this Sound.
Return the number of active channels this sound is playing on.
Return the length of this Sound in seconds.
Channel.play | play a Sound on a specific Channel |
Channel.stop | stop playback on a Channel |
Channel.pause | temporarily stop playback of a channel |
Channel.unpause | resume pause playback of a channel |
Channel.fadeout | stop playback after fading channel out |
Channel.set_volume | set the volume of a playing channel |
Channel.get_volume | get the volume of the playing channel |
Channel.get_busy | check if the channel is active |
Channel.get_sound | get the currently playing Sound |
Channel.queue | queue a Sound object to follow the current |
Channel.get_queue | return any Sound that is queued |
Channel.set_endevent | have the channel send an event when playback stops |
Channel.get_endevent | get the event a channel sends when playback stops |
Return a Channel object for one of the current channels. The id must be a value from 0 to the value of pygame.mixer.get_num_channels.
The Channel object can be used to get fine control over the playback of Sounds. A channel can only playback a single Sound at time. Using channels is entirely optional since pygame can manage them by default.
This will begin playback of a Sound on a specific Channel. If the Channel is currently playing any other Sound it will be stopped. The loops argument controls how many times the sample will be repeated. If loops is -1 then the playback will repeat indefinitely. The time argument can be used to stop playback of the Sound after a given number of milliseconds.
Stop sound playback on a channel. After playback is stopped the channel becomes available for new Sounds to play on it.
Temporarily stop the playback of sound on a channel. It can be resumed at a later time with Channel.unpause
Resume the playback on a paused channel.
Stop playback of a channel after fading out the sound over the given time argument in seconds.
Set the volume of a playing sound. When a channel starts to play its volume value is reset. This only affects the current sound. The value argument is between 0.0 and 1.0.
If one argument is passed, it will be the volume of both speakers. If two arguments are passed and the mixer is in stereo mode, the first argument will be the volume of the left speaker and the second will be the volume of the right speaker. (If the second argument is None, the first argument will be the volume of both speakers.)
This is mixed the the volume of the current Sound object as well.
Return the volume of the channel for the current playing sound. This does not take into account stereo separation used by Channel.set_volume. The Sound object also has its own volume which is mixed with the channel.
Returns true if the channel is activily mixing sound. If the channel is idle this returns False.
Return the actual Sound object currently playing on this channel. If the channel is idle None is returned.
When a Sound is queued on a Channel, it will begin playing immediately after the current Sound is finished. Each channel can only have a single Sound queued at a time. The queued Sound will only play if the current playback finished automatically. It is cleared on any other call to Channel.stop or Channel.play.
If there is no sound actively playing on the Channel then the Sound will begin playing immediately.
If a Sound is already queued on this channel it will be returned. Once the queued sound begind playback it will no longer be on the queue.
When an endevent is set for a channel, it will send an event to the pygame queue every time a sound finished playing. If stop() or play() is called on the Channel it will still post the event.
The type argument will be the event id sent to the queue. If no type argument is given then the Channel will stop sending endevents.
Returns the event type to be sent every time the Channel finishes playback of a Sound. If there is no endevent the function returns pygame.NOEVENT.