# 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.

## Main data types

class sdl2.sdlmixer.Mix_Chunk

  A loaded audio clip to use for playback with the mixer API.

  Chunk objects are created by the `Mix_LoadWAV()` and `Mix_QuickLoad` functions, and should be freed using `Mix_FreeChunk()` when no longer needed.

  allocated

    Whether the associated audio buffer will be freed when the chunk is freed. `1` if the buffer is owned by the chunk, or `0` if it was allocated by a different function.

    Type:

      int

  abuf

    A pointer to the chunk’s audio sample data, in the output format and sample rate of the current mixer.

    Type:

      POINTER(`c_ubyte`)

  alen

    The length of the chunk’s audio buffer (in bytes).

    Type:

      int

  volume

    The volume of the chunk, with 0 being 0% and 127 being 100%.

    Type:

      int

class sdl2.sdlmixer.Mix_Music

  The opaque data type representing a loaded music file.

  Music objects are created by the `Mix_LoadMUS()` family of functions and should be freed using `Mix_FreeMusic()` when no longer needed.

## Initialization and library information functions

sdl2.sdlmixer.Mix_Init(flags)

  Initializes the SDL2_mixer library.

  Calling this function enables support for various audio formats as requested by the init flags. All other audio file formats can be loaded or used regardless of whether this has been called.

  The following init flags are supported:

  Format | Init flag
  --- | ---
  FLAC | `MIX_INIT_FLAC`
  MOD | `MIX_INIT_MID`
  MP3 | `MIX_INIT_MP3`
  MIDI | `MIX_INIT_MID`
  Ogg Vorbis | `MIX_INIT_OGG`
  Opus | `MIX_INIT_OPUS`

  This can be called multiple times to enable support for these formats separately, or can initialize multiple formats at once by passing a set of flags as a bitwise OR. You can also call this function with 0 as a flag to check which audio decoding libraries have already been loaded, or to test whether a given decoder is available on the current system:

      # Initialize FLAC and MP3 support separately
      for flag in [MIX_INIT_FLAC, MIX_INIT_MP3]:
          Mix_Init(flag)
          err = Mix_GetError() # check for any errors loading library
          if len(err):
              print(err)

      # Initialize FLAC and MP3 support at the same time
      flags = MIX_INIT_FLAC | MIX_INIT_MP3
      Mix_Init(flags)
      if Mix_Init(0) != flags: # verify both libraries loaded properly
          print(Mix_GetError())

  Note

  This function is not guaranteed to set an error string on failure, so the return value should be used for error checking instead of just `Mix_GetError()`.

  Parameters:

    flags (int) – A bitwise OR’d set of the flags of the audio formats to load support for.

  Returns:

    A bitmask of all the currently initialized audio decoders.

  Return type:

    int

sdl2.sdlmixer.Mix_Quit()

  De-initializes the SDL_mixer library.

  Calling this function disables support for any formats initialized by `Mix_Init()` and frees all associated memory. You can re-initialize support for those decoders by calling `Mix_Init()` again with the corresponding init flags.

  You only need to call this function once, no matter how many times `Mix_Init()` was called.

sdl2.sdlmixer.Mix_OpenAudio(frequency, format, channels, chunksize)

  Opens the default audio output device for use with the mixer API.

  This function opens the default audio device with a given output channel count, audio sample format, sample rate, and audio buffer size, and initializes the mixer with 8 virtual channels:

      # Initialize a 44.1 kHz 16-bit stereo mixer with a 1024-byte buffer size
      ret = Mix_OpenAudio(44100, sdl2.AUDIO_S16SYS, 2, 1024)
      if ret < 0:
          err = Mix_GetError().decode("utf8")
          raise RuntimeError("Error initializing the mixer: {0}".format(err))

  A sample rate of 44100 Hz (CD quality) or 48000 Hz is recommended for any remotely modern computer. The chunk size must be a power of 8 (e.g. 512, 1024, 2048), and specifies how much audio data to send to the output device at a time. Lower values will have lower latencies, but may introduce skips in the audio (2048 is a safe default). Supported channel counts are 1 (mono), 2 (stereo), 4 (quad), and 6 (5.1 surround).

  For a full list of supported audio format flags, see the list of format values at the following link: https://wiki.libsdl.org/SDL_AudioSpec

  Note

  This should not be called if `SDL_OpenAudio()` has already opened the default audio device (and vice-versa).

  Parameters:

    - frequency (int) – The output sampling rate per channel (in Hz).

    - format (int) – A constant indicating the audio sample format to use with the device (e.g. `sdl2.AUDIO_S16`).

    - channels (int) – The number of output channels to use for the device (e.g. 2 for stereo, 1 for mono).

    - chunksize (int) – The size of the audio buffer (in bytes).

  Returns:

    0 on success, or -1 on error.

  Return type:

    int

sdl2.sdlmixer.Mix_OpenAudioDevice(frequency, format, channels, chunksize, device, allowed_changes)

  Opens a specific audio output device for use with the mixer API.

  A specific audio device can be opened by name using the output of the `SDL_GetAudioDeviceName()` function. Alternatively, passing `None` as the device name will make open the most reasonable default audio device.

  The `allowed_changes` flag specifies which output properties (channel count, frequency, sample format) are allowed to be be automatically changed if not supported by the chosen audio device. See the documentation for `SDL_OpenAudioDevice()` for the list of supported flags and more info.

  See `Mix_OpenAudio()` for more usage details.

  Note

  Once an output device has been opened with this function, it should not be opened again with `SDL_OpenAudioDevice()` (or vice-versa).

  Parameters:

    - frequency (int) – The output sampling rate per channel (in Hz).

    - format (int) – A constant indicating the audio sample format to use with the device (e.g. `sdl2.AUDIO_S16`).

    - channels (int) – The number of output channels to use for the device (e.g. 2 for stereo, 1 for mono).

    - chunksize (int) –

    - device (bytes) – A UTF-8 encoded bytestring of the name of the audio output device to open (or `None` for the default).

    - allowed_changes (int) – A bitmask of flags indicating the output properties allowed to be automatically changed to support the output device. If 0, no changes are allowed.

  Returns:

    0 on success, or -1 on error.

  Return type:

    int

sdl2.sdlmixer.Mix_CloseAudio()

  Shuts down and de-initializes the mixer API.

  Calling this function stops all audio playback and closes the current mixer device. Once called, the mixer API should not be used until re-initialized with `Mix_OpenAudioDevice()`.

  Note

  If `Mix_OpenAudioDevice()` has been called multiple times, this must be called an equal number of times to actually de-initialize the API.

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

sdl2.sdlmixer.Mix_QuerySpec(frequency, format, channels)

  Retrieves the actual audio format in use by the current mixer device.

  This function returns the calculated info by reference, meaning that it needs to be called using pre-allocated ctypes variables:

      from ctypes import c_int, byref

      freq, fmt, chans = c_int(0), c_int(0), c_int(0)
      ret = Mix_QuerySpec(byref(freq), byref(fmt), byref(chans))
      if ret > 0:
          results = [x.value for x in (freq, fmt, chans)]

  The obtained values may or may not match the parameters you passed to `Mix_OpenAudio()`, depending on the audio configurations supported by the output device.

  Parameters:

    - frequency (byref(`c_int`)) – The output sampling rate per channel (in Hz).

    - format (byref(`c_int`)) – The output format used by the output device.

    - channels (byref(`c_int`)) – The number of output channels used by the device (e.g. 2 for stereo, 1 for mono).

  Returns:

    The number of times the mixer device has been opened, or 0 on error.

  Return type:

    int

sdl2.sdlmixer.Mix_Linked_Version()

  Gets the version of the dynamically-linked SDL2_mixer library.

  Returns:

    A pointer to a structure containing the version of the SDL2_mixer library currently in use.

  Return type:

    POINTER(`SDL_version`)

## Audio loading and closing functions

### Loading and closing audio clips

sdl2.sdlmixer.Mix_LoadWAV(file)

  Loads an audio clip from a file.

  See `Mix_GetChunkDecoder()` for a list of supported file types.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used in order to determine the correct output format for playback.

  Parameters:

    file (bytes) – A UTF8-encoded bytestring containing the path of the audio clip to load.

  Returns:

    A pointer to the chunk containing the loaded audio.

  Return type:

    POINTER(`Mix_Chunk`)

sdl2.sdlmixer.Mix_LoadWAV_RW(src, freesrc)

  Loads an audio clip from an SDL2 file object.

  See `Mix_GetChunkDecoder()` for a list of supported file types.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used in order to determine the correct output format for playback.

  Parameters:

    - src (`SDL_RWops`) – A file object containing a valid audio clip.

    - freesrc (int) – If non-zero, the provided file object will be closed and freed automatically after being loaded.

  Returns:

    A pointer to the chunk containing the loaded audio.

  Return type:

    POINTER(`Mix_Chunk`)

sdl2.sdlmixer.Mix_QuickLoad_WAV(mem)

  Loads a memory buffer as a WAV file.

  Unlike `Mix_LoadWAV_RW()`, this function performs no audio format conversion or error checking, and assumes that the WAV in the buffer is already in the correct output format for the mixer. Unless high performance is a must, `Mix_LoadWAV_RW()` is a more flexible and much safer option.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used.

  Parameters:

    mem (POINTER(`c_byte`)) – A pointer to a memory buffer containing a valid WAVE audio file.

  Returns:

    A pointer to the chunk containing the loaded audio.

  Return type:

    POINTER(`Mix_Chunk`)

sdl2.sdlmixer.Mix_QuickLoad_RAW(mem, len)

  Loads a memory buffer as a raw audio clip.

  This function performs no error checking and assumes that the data in the buffer is in the correct output format for the mixer.

  This can be used for converting Numpy arrays or other Python data types into audio clips for use with the mixer API. For example, to generate a pure sine wave tone at a given frequency, you could use the following code:

      import ctypes
      import numpy as np

      duration = 3      # Seconds of sound
      hz = 432          # Frequency of the generated tone
      dtype = np.int16  # Mixer output format is signed 16-bit int
      max_int = 32767   # The max/min value for a signed 16-bit int
      srate = 44100     # Sample rate for each channel is 44100 kHz

      # Generate a 3 sec. sine wave for a 2-channel, 44100 Hz, AUDIO_S16 mixer
      size = int((duration / 1000.0) * srate)
      arr = np.sin(np.pi * np.arange(size) / srate * hz) * max_int

      # Cast the array into ctypes format for use with mixer
      arr_bytes = arr.tostring()
      buflen = len(arr_bytes)
      c_buf = (ctypes.c_ubyte * buflen).from_buffer_copy(arr_bytes)

      # Convert the ctypes memory buffer into a mixer audio clip
      sine_chunk = Mix_QuickLoad_RAW(
          ctypes.cast(c_buf, ctypes.POINTER(ctypes.c_ubyte)), buflen
      )

  Note

  You must keep a reference to the created ctypes buffer as long as the resulting audio clip is in use. Otherwise, Python may automatically free the memory associated with the audio buffer, meaning that any subsequent attempts to play the clip will result in a segmentation fault.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used.

  Parameters:

    - mem (POINTER(`c_byte`)) – A pointer to a memory buffer containing audio samples in the current output format.

    - len (int) – The length (in bytes) of the memory buffer to load.

  Returns:

    A pointer to the chunk containing the loaded audio.

  Return type:

    POINTER(`Mix_Chunk`)

sdl2.sdlmixer.Mix_FreeChunk(chunk)

  Closes and frees the memory associated with a given audio clip.

  This function should be called on a chunk when you are done with it. A `Mix_Chunk` cannot be used after it has been closed.

  Parameters:

    chunk (`Mix_Chunk`) – The chunk object to close.

### Loading and closing music

sdl2.sdlmixer.Mix_LoadMUS(file)

  Loads music from a file.

  See `Mix_GetMusicDecoder()` for a list of supported file types.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used in order to determine the correct output format for playback.

  Parameters:

    file (bytes) – A UTF8-encoded bytestring containing the path of the music file to load.

  Returns:

    A pointer to the object containing the loaded music.

  Return type:

    POINTER(`Mix_Music`)

sdl2.sdlmixer.Mix_LoadMUS_RW(src, freesrc)

  Loads music from an SDL2 file object.

  See `Mix_GetMusicDecoder()` for a list of supported file types.

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used in order to determine the correct output format for playback.

  Parameters:

    - src (`SDL_RWops`) – A file object containing a valid music format.

    - freesrc (int) – If non-zero, the provided file object will be closed and freed automatically after being loaded.

  Returns:

    A pointer to the object containing the loaded music.

  Return type:

    POINTER(`Mix_Music`)

sdl2.sdlmixer.Mix_LoadMUSType_RW(src, type, freesrc)

  Loads music from an SDL2 file object with a specific decoder.

  This function supports the following audio format constants:

  Format | Constant
  --- | ---
  None (autodetect) | `MUS_NONE`
  External command | `MUS_CMD`
  WAVE format | `MUS_WAV`
  Amiga MOD format | `MUS_MOD`
  MIDI format | `MUS_MID`
  Ogg Vorbis | `MUS_OGG`
  MP3 format | `MUS_MP3`
  FLAC format | `MUS_FLAC`
  Opus format | `MUS_OPUS`

  Note

  `Mix_OpenAudioDevice()` must be called before this function can be used in order to determine the correct output format for playback.

  Parameters:

    - src (`SDL_RWops`) – A file object containing a valid music format.

    - type (int) – The decoder to use for loading the file object.

    - freesrc (int) – If non-zero, the provided file object will be closed and freed automatically after being loaded.

  Returns:

    A pointer to the object containing the loaded music.

  Return type:

    POINTER(`Mix_Music`)

sdl2.sdlmixer.Mix_FreeMusic(music)

  Closes and frees the memory associated with a given music object.

  This function should be called on a music object when you are done with it. A `Mix_Music` cannot be used after it has been closed.

  Parameters:

    music (`Mix_Music`) – The music object to close.

## Decoder availability & info functions

sdl2.sdlmixer.Mix_GetNumChunkDecoders()

  Retrieves the number of available audio chunk decoders.

  The returned value can differ between runs of a program due to changes in the availability of the shared libraries required for supporting different formats.

  Returns:

    The number of available audio chunk decoders.

  Return type:

    int

sdl2.sdlmixer.Mix_GetChunkDecoder(index)

  Retrieves the name of a given audio chunk decoder.

  The SDL_mixer library currently supports the following chunk decoders:

  Decoder Name | Format Type | Notes
  --- | --- | ---
  b”FLAC” | Free Lossless Audio Codec |
  b”MOD” | Amiga MOD format |
  b”MP3” | MP3 format |
  b”OGG” | Ogg Vorbis |
  b”MID” | MIDI format | Not always available on Linux
  b”OPUS” | Opus Interactive Audio Codec | Added in SDL_mixer 2.0.4
  b”WAVE” | Waveform Audio File Format |
  b”AIFF” | Audio Interchange File Format |
  b”VOC” | Creative Voice file |

  Use the `Mix_GetNumChunkDecoders()` function to get the number of available chunk decoders.

  Returns:

    The name of the given chunk decoder, or `None` if the index is invalid.

  Return type:

    bytes

sdl2.sdlmixer.Mix_HasChunkDecoder(name)

  Checks whether a specific chunk decoder is available.

  See `Mix_GetChunkDecoder()` for a list of valid decoder names.

  Parameters:

    name (bytes) – A bytestring of the name of the decoder to query.

  Returns:

    1 if the decoder is present, or 0 if unavailable.

  Return type:

    int

sdl2.sdlmixer.Mix_GetNumMusicDecoders()

  Retrieves the number of available music decoders.

  The returned value can differ between runs of a program due to changes in the availability of the shared libraries required for supporting different formats.

  Returns:

    The number of available music decoders.

  Return type:

    int

sdl2.sdlmixer.Mix_GetMusicDecoder(index)

  Retrieves the name of a given music decoder.

  The SDL_mixer library currently supports the following music decoders:

  Decoder Name | Format Type | Notes
  --- | --- | ---
  b”FLAC” | Free Lossless Audio Codec |
  b”MOD” | Amiga MOD |
  b”MP3” | MP3 format |
  b”OGG” | Ogg Vorbis |
  b”MIDI” | MIDI format | Not always available on Linux
  b”OPUS” | Opus Interactive Audio Codec | Added in SDL_mixer 2.0.4
  b”CMD | External music command | Not available on Windows
  b”WAVE” | Waveform Audio File Format |

  Use the `Mix_GetNumMusicDecoders()` function to get the number of available chunk decoders.

  Returns:

    The name of the given music decoder, or `None` if the index is invalid.

  Return type:

    bytes

sdl2.sdlmixer.Mix_HasMusicDecoder(name)

  Checks whether a specific music decoder is available.

  See `Mix_GetMusicDecoder()` for a list of valid decoder names.

  Parameters:

    name (bytes) – A bytestring of the name of the decoder to query.

  Returns:

    1 if the decoder is present, or 0 if unavailable.

  Return type:

    int

sdl2.sdlmixer.Mix_GetMusicType(music)

  Gets the format of a given music object.

  See `Mix_LoadMUSType_RW()` for a list of the possible type constants.

  Parameters:

    music (`Mix_Music`) – The music object for which the type will be retrieved.

  Returns:

    A constant indicating the format of the music object, or `MUS_NONE` (0) if the format could not be identified.

  Return type:

    int

## Music metadata functions

sdl2.sdlmixer.Mix_GetMusicTitle(music)

  Gets the song title for a given music object.

  If a title is not available in the music metadata, the file name will be returned instead. If no music is playing, this will return an empty string.

  Parameters:

    music (`Mix_Music`) – The music object from which to retrieve the title.

  Returns:

    The song title of the music object.

  Return type:

    bytes

sdl2.sdlmixer.Mix_GetMusicTitleTag(music)

  Gets the song title for a given music object.

  Unlike `Mix_GetMusicTitle()`, this function only checks for a title in the music metadata and will return an empty string instead of the file name if no title tag is present.

  If no music is playing, this will return an empty string.

  Parameters:

    music (`Mix_Music`) – The music object from which to retrieve the title.

  Returns:

    The song title of the music object.

  Return type:

    bytes

sdl2.sdlmixer.Mix_GetMusicArtistTag(music)

  Gets the artist name for a given music object.

  If the music metadata has no artist tag or no music is playing, this will return an empty string.

  Parameters:

    music (`Mix_Music`) – The music object from which to retrieve the artist.

  Returns:

    The artist name for the music object.

  Return type:

    bytes

sdl2.sdlmixer.Mix_GetMusicAlbumTag(music)

  Gets the album name for a given music object.

  If the music metadata has no album tag or no music is playing, this will return an empty string.

  Parameters:

    music (`Mix_Music`) – The music object from which to retrieve the album name.

  Returns:

    The album name for the music object.

  Return type:

    bytes

sdl2.sdlmixer.Mix_GetMusicCopyrightTag(music)

  Gets the copyright text for a given music object.

  If the music metadata has no copyright tag or no music is playing, this will return an empty string.

  Parameters:

    music (`Mix_Music`) – The music object from which to retrieve the copyright text.

  Returns:

    The copyright text for the music object.

  Return type:

    bytes

## Channel functions

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

### Channel configuration

sdl2.sdlmixer.Mix_AllocateChannels(numchans)

  Sets the number of channels to use for the mixer API.

  In this context, “channels” refers to the number of virtual channels used by the mixer API for playing multiple sounds simultaneously. It does not refer to the physical number of channels to use for the output device.

  This can be called multiple times, even with sounds playing. If `numchans` is less than the current number of channels, the channels above the new number will be stopped, freed, and not mixed any longer. If any channels are deallocated, any callback set by `Mix_ChannelFinished()` will be called when each channel is halted to be freed.

  If this function is called with a negative number (e.g. `-1`), it will return the number of currently-allocated virtual mixer channels without changing anything. If called with 0, all mixer channels will be freed.

  This function has no effect on music playback.

  Parameters:

    numchans (int) – The number of virtual channels to use for the mixer API, or a negative number to query the current allocated channel count.

sdl2.sdlmixer.Mix_ReserveChannels(num)

sdl2.sdlmixer.Mix_ChannelFinished(channel_finished)

### Channel grouping

sdl2.sdlmixer.Mix_GroupChannel(which, tag)

sdl2.sdlmixer.Mix_GroupChannels(from_, to, tag)

sdl2.sdlmixer.Mix_GroupAvailable(tag)

sdl2.sdlmixer.Mix_GroupCount(tag)

sdl2.sdlmixer.Mix_GroupOldest(tag)

sdl2.sdlmixer.Mix_GroupNewer(tag)

sdl2.sdlmixer.Mix_HaltGroup(tag)

sdl2.sdlmixer.Mix_FadeOutGroup(tag, ms)

## Playback functions

### Channel playback

sdl2.sdlmixer.Mix_PlayChannel(channel, chunk, loops)

  Play an audio chunk on a specific channel.

  If the specified channel is -1, the chunk will be played on the first free channel (if no free channel is available, an error is returned).

  If a specific channel was requested and there is a chunk already playing there, that chunk will be halted and the new chunk will take its place.

  If `loops` is greater than zero, the chunk will loop the specified number of times. If `loops` is set to -1, the chunk will loop “infinitely” (~65000 times).

  Parameters:

    - channel (int) – The channel on which to play the new chunk.

    - chunk (`Mix_Chunk`) – The sound to play.

    - loops (int) – The number of times the chunk should loop (0 to play once, -1 to loop infinitely).

  Returns:

    The index of the channel used to play the sound, or -1 if the sound could not be played.

  Return type:

    int

sdl2.sdlmixer.Mix_PlayChannelTimed(channel, chunk, loops, ticks)

  Play an audio chunk on a specific channel for a given duration.

  This function is the same as `Mix_PlayChannel()` except that you can specify the maximum number of milliseconds for the sound to be played before it is halted.

  Parameters:

    - channel (int) – The channel on which to play the new chunk.

    - chunk (`Mix_Chunk`) – The sound to play.

    - loops (int) – The number of times the chunk should loop (0 to play once, -1 to loop infinitely).

    - ticks (int) – The maximum number of milliseconds to play the chunk on the channel before halting.

  Returns:

    The index of the channel used to play the sound, or -1 if the sound could not be played.

  Return type:

    int

sdl2.sdlmixer.Mix_FadeInChannel(channel, chunk, loops, ms)

sdl2.sdlmixer.Mix_FadeInChannelTimed(channel, chunk, loops, ms, ticks)

sdl2.sdlmixer.Mix_Pause(channel)

  Pauses playback of a given mixer channel.

  This temporarily stops playback on the given channel. When resumed via `Mix_Resume()`, the channel will continue to play where it left off.

  Playing a new chunk on a channel when the channel is paused will replace the the chunk and unpause the channel.

  Parameters:

    channel (int) – The index of the channel to pause (or -1 to pause all channels).

sdl2.sdlmixer.Mix_Resume(channel)

  Resumes playback of a given mixer channel.

  This will resume playback of the channel if it has been paused. If the channel is already playing, this will have no effect.

  Parameters:

    channel (int) – The index of the channel to resume (or -1 to resume all channels).

sdl2.sdlmixer.Mix_HaltChannel(channel)

  Halt playback of a particular channel.

  This will stop playback on the specified channel until a new chunk is played there. Specifying a channel of -1 will halt all non-music channels.

  Any halted channels will have any currently-registered effects deregistered, and will call any callback specified by `Mix_ChannelFinished()` before this function returns.

  Parameters:

    channel (int) – The index of the channel to halt, or -1 to halt all channels.

  Returns:

    0 on success, or -1 on error.

  Return type:

    int

sdl2.sdlmixer.Mix_ExpireChannel(channel, ticks)

sdl2.sdlmixer.Mix_FadeOutChannel(which, ms)

### Music playback

sdl2.sdlmixer.Mix_PlayMusic(music, loops)

  Play a new music object.

  In SDL_mixer there is only ever one music object playing at a time; if this is called while another music object is playing, the previous music will be replaced with the new music.

  Please note that if the currently-playing music is in the process of fading out (via `Mix_FadeOutMusic()`), this function will block until the fade completes. If you need to avoid this, be sure to call `Mix_HaltMusic()` before calling this function.

  Parameters:

    - music (`Mix_Music`) – The new music to play on the music channel.

    - loops (int) – The number of loops to play the music for (if 0, will only play once).

  Returns:

    0 on success, or -1 on error.

  Return type:

    int

sdl2.sdlmixer.Mix_FadeInMusic(music, loops, ms)

sdl2.sdlmixer.Mix_FadeInMusicPos(music, loops, ms, position)

sdl2.sdlmixer.Mix_PauseMusic()

  Pauses playback of the music channel.

  This temporarily stops playback on the music channel. When resumed via `Mix_ResumeMusic()`, the music will continue to play where it left off.

  Playing a new music object when the music channel is paused will replace the current music and unpause the music stream.

sdl2.sdlmixer.Mix_ResumeMusic()

  Resumes playback of the music channel.

  This will resume playback of the music channel if it has been paused. If the music channel is already playing, this will have no effect.

sdl2.sdlmixer.Mix_RewindMusic()

  Sets the music channel to the beginning of the currently loaded music.

  This can be called regardless of whether music is currently playing.

sdl2.sdlmixer.Mix_ModMusicJumpToOrder(order)

sdl2.sdlmixer.Mix_SetMusicPosition(position)

sdl2.sdlmixer.Mix_HaltMusic()

  Halt playback of the music channel.

  This will stop playback on music channel until a new music object is played.

  Halting the music channnel will call any callback set by `Mix_HookMusicFinished()` before this function returns.

  Returns:

    0, regardless of whether any music was halted.

  Return type:

    int

sdl2.sdlmixer.Mix_FadeOutMusic(ms)

sdl2.sdlmixer.Mix_HookMusicFinished(music_finished)

## Volume functions

sdl2.sdlmixer.Mix_Volume(channel, volume)

sdl2.sdlmixer.Mix_VolumeChunk(chunk, volume)

sdl2.sdlmixer.Mix_VolumeMusic(volume)

sdl2.sdlmixer.Mix_GetMusicVolume(music)

sdl2.sdlmixer.Mix_MasterVolume(volume)

## Playback status functions

sdl2.sdlmixer.Mix_Playing(channel)

  Checks whether a chunk has been loaded into a given channel.

  Note that this will return 1 even if the channel is paused: this only checks whether the channel is ready for playback or not. It will return 0 if no chunk is currently loaded into the channel.

  Parameters:

    channel (int) – The index of the channel to query (or -1 to count the total number of playback-ready channels).

  Returns:

    1 if a chunk is loaded in the given channel, otherwise 0. Alternatively, if channel is `-1`, returns the number of mixer channels ready for playback.

  Return type:

    int

sdl2.sdlmixer.Mix_Paused(channel)

  Checks whether a given mixer channel is currently paused.

  Parameters:

    channel (int) – The index of the channel to query (or -1 to count the total number of paused channels).

  Returns:

    1 if the channel is paused, otherwise 0. Alternatively, if channel is `-1`, returns the number of currently paused mixer channels.

  Return type:

    int

sdl2.sdlmixer.Mix_FadingChannel(which)

sdl2.sdlmixer.Mix_GetChunk(channel)

sdl2.sdlmixer.Mix_PlayingMusic()

  Checks whether music has been loaded into the music channel.

  Note that this will return 1 even if the channel is paused: this only checks whether the music channel is ready for playback or not. It will return 0 if no music is currently loaded into the channel.

  Returns:

    1 if music is loaded in the music channel, otherwise 0.

  Return type:

    int

sdl2.sdlmixer.Mix_PausedMusic()

  Checks whether the music channel is currently paused.

  Returns:

    1 if the music channel is paused, otherwise 0.

  Return type:

    int

sdl2.sdlmixer.Mix_FadingMusic()

sdl2.sdlmixer.Mix_GetMusicPosition(music)

sdl2.sdlmixer.Mix_MusicDuration(music)

sdl2.sdlmixer.Mix_GetMusicLoopStartTime(music)

sdl2.sdlmixer.Mix_GetMusicLoopEndTime(music)

sdl2.sdlmixer.Mix_GetMusicLoopLengthTime(music)

## Effects-processing functions

sdl2.sdlmixer.Mix_RegisterEffect(chan, f, d, arg)

sdl2.sdlmixer.Mix_UnregisterEffect(channel, f)

sdl2.sdlmixer.Mix_UnregisterAllEffects(channel)

sdl2.sdlmixer.Mix_SetPanning(channel, left, right)

sdl2.sdlmixer.Mix_SetPosition(channel, angle, distance)

sdl2.sdlmixer.Mix_SetDistance(channel, distance)

sdl2.sdlmixer.Mix_SetReverseStereo(channel, flip)

sdl2.sdlmixer.Mix_SetPostMix(mix_func, arg)

## Decoder-specific functions

### External music playback functions

sdl2.sdlmixer.Mix_SetMusicCMD(command)

sdl2.sdlmixer.Mix_HookMusic(mix_func, arg)

sdl2.sdlmixer.Mix_GetMusicHookData()

### MikMod configuration functions

sdl2.sdlmixer.Mix_SetSynchroValue(value)

sdl2.sdlmixer.Mix_GetSynchroValue()

### MIDI configuration functions

sdl2.sdlmixer.Mix_SetSoundFonts(paths)

sdl2.sdlmixer.Mix_GetSoundFonts()

sdl2.sdlmixer.Mix_EachSoundFont(function, data)

sdl2.sdlmixer.Mix_SetTimidityCfg(path)

sdl2.sdlmixer.Mix_GetTimidityCfg()