A small linux shared library which plays music files. Written in C.
- Depends only on libc (2.39+). If you have something equal or more modern than Ubuntu 24 it should just work.
- Supports the most popular music formats (mp3, flac, m4a, wav, aac, ogg) with different codecs in them.
- Built on top of ffmpeg and SDL3. I'm not that crazy (yet) to write so much code by myself.
Public library interface is defined and documented in libmsp.h header.
libmsp uses two threads:
- Main thread to push user commands to the playback thread with one exception:
msp_get_metadata()works in the main thread. All other functions are expected to return instantly and won't block your app. - Playback thread listens commands in a loop, and also does dirty decoding work if it requested to play something.
It does not decode many frames ahead and does not waste much CPU.
Usage general steps are:
- Initialize playback context.
- Use functions to play, pause, etc.
- Deinitialize to free inner resources.
For usage example see testapp.c (WIP)
The minimal code sample:
#include "../src/libmsp.h"
#include <unistd.h>
int main() {
playback_context_t *player = msp_init();
msp_play(player, "music.mp3");
sleep(10); // without sleep msp_play() instantly returns and you won't hear anything
msp_deinit(player);
return 0;
}- linux (for local build, container build should work on any platform). I didn't test it anywhere else.
- cmake
- gcc
- just
- podman
First of all, you can check just --list and see full list of available recipes.
The build itself consists of two parts: 1. ffmpeg static build 2. every other stuff build. The 1st part historically
builds only in a container, because I wanted to get reproducible builds while figuring out what demuxers and codecs I can
and what I can't turn off. So for now even for a local build you need podman.
The 2nd part - library itself - could be built in a container or locally.
Ready for distribution release build
just podman-build
And see ./dist folder for .so
Builds ffmpeg-static in podman, copies it to the host, and builds libmsp locally. Also builds testapp binary.
just build
- Because I can :)
- I have a pet-project music player with Godot UI (because why not), and it needs a good playback backend.
I tried LibVLC, and it is great, but it has a bunch of dependencies, basically it requires whole vlc package to work, and C# wrapper nuget package for LibVLC does not include any native libs at all. And I want a self-contained binary.
Also, Godot does not include native libs into distribution by default, so you have to deal with LD_LIBRARY_PATH hacks etc.
So, I decided to build own minimalistic library and ship it in nuget package. C# wrapper is here. - This is a great opportunity for me to code something in a system language.
It stands for "My Stupid Player"