mixLoadMus function

Pointer<MixMusic> mixLoadMus(
  1. String? file
)

Load a supported audio format into a music object.

SDL_mixer has two separate data structures for audio data. One it calls a "chunk," which is meant to be a file completely decoded into memory up front, and the other it calls "music" which is a file intended to be decoded on demand. Originally, simple formats like uncompressed WAV files were meant to be chunks and compressed things, like MP3s, were meant to be music, and you would stream one thing for a game's music and make repeating sound effects with the chunks.

In modern times, this isn't split by format anymore, and most are interchangeable, so the question is what the app thinks is worth predecoding or not. Chunks might take more memory, but once they are loaded won't need to decode again, whereas music always needs to be decoded on the fly. Also, crucially, there are as many channels for chunks as the app can allocate, but SDL_mixer only offers a single "music" channel.

When done with this music, the app should dispose of it with a call to Mix_FreeMusic().

\param file a file path from where to load music data. \returns a new music object, or NULL on error.

\since This function is available since SDL_mixer 2.0.0.

\sa Mix_FreeMusic

extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file)

Implementation

Pointer<MixMusic> mixLoadMus(String? file) {
  final mixLoadMusLookupFunction = libSdl2Mixer.lookupFunction<
      Pointer<MixMusic> Function(Pointer<Utf8> file),
      Pointer<MixMusic> Function(Pointer<Utf8> file)>('Mix_LoadMUS');
  final filePointer = file != null ? file.toNativeUtf8() : nullptr;
  final result = mixLoadMusLookupFunction(filePointer);
  calloc.free(filePointer);
  return result;
}