sdl2.sdlmixer - Python bindings for SDL_mixer

The sdl2.sdlmixer module provides bindings for wrapper the SDL_mixer audio playback library. It supports loading, playing, and mixing audio from a wide range of popular formats (e.g. WAV, FLAC, MP3, OGG).

The SDL_mixer library is designed around the concept of virtual channels, each of which can be set to different volumes, have different left/right panning, and play different effects and sounds simultaneously (like a mixing board in a recording studio). In addition to the main mixing channels, SDL_mixer also provides a single channel for music playback, which is less flexible than the other channels but supports a wider range of playback formats (including MIDI) and requires less memory for playback.

Music playback is performed using Mix_Music objects and their corresponding functions. All other audio playback is performed using Mix_Chunk objects.

Note

The PySDL2 documentation for this module is currently a work-in-progress, and not all functions are documented. The official C documentation (linked below) can be used in the meantime to fill in any gaps.

The official documentation for the SDL_mixer library can be found here. Note that not all functions may be documented, as the official doucmentation is currently several releases out-of-date.

Initialization and library information functions

sdl2.sdlmixer.Mix_GetError()

Returns the most recently encountered SDL2 error message, if any.

This function is a simple wrapper around SDL_GetError().

Retuns:A UTF-8 encoded string describing the most recent SDL2 error.
Return type:bytes
sdl2.sdlmixer.Mix_SetError(fmt)

Sets the most recent SDL2 error message to a given string.

This function is a simple wrapper around SDL_SetError().

Parameters:fmt (bytes) – A UTF-8 encoded string containing the error message to set.
Retuns:Always returns -1.
Return type:int

Channel functions

These functions affect regular mixer channels. Music is not affected by these functions.