pb-macos-audioplayer

Mac OSX specific forum
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

pb-macos-audioplayer

Post by deseven »

A simple wrapper built around macOS AVAudioPlayer. Totally asynchronous, but NOT threadsafe. Should support mp3, m4a, aac, wav, aiff, alac natively and everything else with the help of FFmpeg.

Basic usage:

Code: Select all

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
The most recent version and more complex example can be found on github: https://github.com/deseven/pb-macos-audioplayer
Last edited by deseven on Wed Nov 10, 2021 3:02 pm, edited 2 times in total.
mrbungle
Enthusiast
Enthusiast
Posts: 111
Joined: Wed Dec 30, 2020 3:18 am

Re: pb-macos-audioplayer

Post by mrbungle »

thank you!
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: pb-macos-audioplayer

Post by mk-soft »

Hello Deseven,

if you finally use the return value for Boolean in procedures no longer "Procedure.b foo()", but simply "Procedure foo()", everything is good.

If you use type ".b" (byte), it must be additionally filtered in the ASM code and thus generates more unnecessary ASM code.

;)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

Ah, thanks for the clarification, I'm not even sure where i got this habit from.
Updated the code.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

In the new version I decided to get rid of PB sound library, since it's completely broken, see:
viewtopic.php?f=24&t=77779
viewtopic.php?f=24&t=78013
viewtopic.php?f=24&t=77630

And with the amount of attention macOS build of PB gets these days it's very likely that it won't be fixed for several years or at all.

So this module now uses FFmpeg to cover formats not supported natively by AVAudioPlayer, such as FLAC or OGG. It's totally optional and if you don't need to play those then nothing needs to be done :)

More info in the readme - https://github.com/deseven/pb-macos-aud ... /README.md
Last edited by deseven on Wed Nov 10, 2021 4:30 pm, edited 1 time in total.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

Updated once again, you can now create multiple instances by defining the ID or just passing #PB_Any as a first argument.
mrbungle
Enthusiast
Enthusiast
Posts: 111
Joined: Wed Dec 30, 2020 3:18 am

Re: pb-macos-audioplayer

Post by mrbungle »

Thank you for making this!
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: pb-macos-audioplayer

Post by kenmo »

I don't have an *immediate* need for this, but still, thank you deseven!
jamirokwai
Enthusiast
Enthusiast
Posts: 771
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: pb-macos-audioplayer

Post by jamirokwai »

Great! Thanks, that may be useful in the near future :-)
Regards,
JamiroKwai
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

Thanks for the kind words, guys!
I mostly wrote it for my macOS music player, but it's great if someone else can find it useful.
jamirokwai
Enthusiast
Enthusiast
Posts: 771
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: pb-macos-audioplayer

Post by jamirokwai »

Hi deseven,

I just checked out your player. Nice!
However, in main.pb, PB 5.7.3 throws the error "Line 146: setCurrentTime(): Incorrect number of parameters.". Maybe, the player-component I downloaded from GItHub is too new...

One perfect addition would be internet-radio stations by URL, maybe using BASS? This way, I could ditch iTunes ;-)
And you could let users show the player, where ffmpeg and other tools and libraries reside.
Regards,
JamiroKwai
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

Hi. Glad you liked it :)
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm However, in main.pb, PB 5.7.3 throws the error "Line 146: setCurrentTime(): Incorrect number of parameters.". Maybe, the player-component I downloaded from GItHub is too new...
Yeah, I've uploaded the latest changes for ichm, now it should be buildable with the latest version of all modules.
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm One perfect addition would be internet-radio stations by URL, maybe using BASS? This way, I could ditch iTunes
Sorry, no plans for that at all, there are many players for macOS that already do that perfectly. Maybe someday, but definitely not in the near future, there are many other things I want to introduce as soon as possible.
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm And you could let users show the player, where ffmpeg and other tools and libraries reside.
Not sure what you mean by this, can you explain?
jamirokwai
Enthusiast
Enthusiast
Posts: 771
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: pb-macos-audioplayer

Post by jamirokwai »

deseven wrote: Fri Nov 12, 2021 2:15 pm Hi. Glad you liked it :)
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm However, in main.pb, PB 5.7.3 throws the error "Line 146: setCurrentTime(): Incorrect number of parameters.". Maybe, the player-component I downloaded from GItHub is too new...
Yeah, I've uploaded the latest changes for ichm, now it should be buildable with the latest version of all modules.

Great. I will have a look!
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm One perfect addition would be internet-radio stations by URL, maybe using BASS? This way, I could ditch iTunes
Sorry, no plans for that at all, there are many players for macOS that already do that perfectly. Maybe someday, but definitely not in the near future, there are many other things I want to introduce as soon as possible.

Ok. Sounds reasonable ;-)
Maybe, I have some time to look into it. After all, you open sourced the player.
jamirokwai wrote: Fri Nov 12, 2021 1:09 pm And you could let users show the player, where ffmpeg and other tools and libraries reside.
Not sure what you mean by this, can you explain?
You open preferences window, and if your player didn't find the appropriate ffmpeg or lyrics-lib, etc, it opens a OpenFileRequester() and lets the user point to the binary.
Regards,
JamiroKwai
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: pb-macos-audioplayer

Post by deseven »

jamirokwai wrote: Fri Nov 12, 2021 3:21 pm You open preferences window, and if your player didn't find the appropriate ffmpeg or lyrics-lib, etc, it opens a OpenFileRequester() and lets the user point to the binary.
Ah, I see.
FFmpeg is included in the release, it's a part of the distribution (releases are here - https://github.com/deseven/iCanHazMusic/releases)
External lyrics module is a very temporary solution, I plan to get rid of it in time. Ideally the application should be self-sufficient.
Post Reply