A simple wrapper built around macOS AVAudioPlayer for PureBasic. Totally asynchronous, but NOT threadsafe. Should support mp3, m4a, aac, wav, aiff, alac natively and everything else with the help of FFmpeg.
IncludeFile "audioplayer.pbi"
If audioplayer::load(0,"file.mp3")
Debug "Playing file " + audioplayer::getPath(0)
Debug "File duration: " + StrD(audioplayer::getDuration(0)) + " sec"
audioplayer::play(0)
Delay(5100)
audioplayer::pause(0)
Debug "Played: " + StrD(audioplayer::getCurrentTime(0)) + " sec"
audioplayer::stop(0)
audioplayer::free(0)
EndIf
For advanced usage check out the included example.pb
.
In order to support additional formats, FFMpeg can be used by defining its path with audioplayer::setFFmpegPath(path.s)
and needed formats with audioplayer::addFFmpegFormat(ext.s)
. This is totally optional and the module works with native formats without any external stuff. In case you want to have a portable FFmpeg and use it with your project, here's your options:
- You can simply grab FFmpeg from here.
- I made a build script that builds statically-linked (i.e. portable) FFmpeg that can process ape, flac, ogg and wv files, with a binary of just 1.4MB, you can find it here. Also check the one it's based on.
- Build it yourself depending on what you need, start here.
Don't forget to check legal information here - https://www.ffmpeg.org/legal.html