Trying libvlc VLC Player

Mac OSX specific forum
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Trying libvlc VLC Player

Post by Justin »

Has anyone tried libvlc with macos? it works with windows and linux but not in macos.
I think the critical call is libvlc_media_player_set_nsobject() i used a canvas but does not work.
Main page https://www.videolan.org/index.html
API https://www.videolan.org/developers/vlc ... 198acc31f6
You need to install vlc player.
This code creates a player and a media instances but it does not play:

Code: Select all


EnableExplicit

Define.i win, canvas
Define.i vlcInst, vlcPlayer
Define.s libstr
Define.i lib, media

Define.s path, mediaPath

path = "/Applications/VLC.app/Contents/MacOS/lib/"
SetEnvironmentVariable("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins/")
libstr = "libvlc.dylib"

lib = OpenLibrary(#PB_Any, path + libstr)

win = OpenWindow(#PB_Any, 10, 10, 400, 300, "", #PB_Window_SystemMenu)
canvas = CanvasGadget(#PB_Any, 0, 0, 400, 300, #PB_Canvas_Container)

vlcInst = CallFunction(lib, "libvlc_new", 0, #Null)
Debug vlcInst

vlcPlayer = CallFunction(lib, "libvlc_media_player_new", vlcInst)
Debug vlcPlayer
CallFunction(lib, "libvlc_media_player_set_nsobject", vlcPlayer, GadgetID(canvas))
mediaPath = "yourmediafile.mp4"
media = CallFunction(lib, "libvlc_media_new_path", vlcInst, @mediaPath)
Debug media
CallFunction(lib, "libvlc_media_player_set_media", vlcPlayer, media)

CallFunction(lib, "libvlc_media_player_play", vlcPlayer)

Repeat
  
Until WaitWindowEvent() = #PB_Event_CloseWindow
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Trying libvlc VLC Player

Post by Wolfram »

The Code works here. OSX 10.7, PB 5.45, ASCI Mode and without #PB_Canvas_Container (because not supported in PB 5.45).
macOS Catalina 10.15.7
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Trying libvlc VLC Player

Post by Justin »

Strange, it does not work here on PB 5.60 64bit wihout #PB_Canvas_Container although i am running OSX 10.11 64bit on virtualbox, can someone test 5.60 on a real machine?
Are you running PB 32 or 64 bit?
Maybe Fred could give us some hint on what has changed in the canvas?
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Trying libvlc VLC Player

Post by Wolfram »

PB 5.6 is unicode only.
So you have to change this line.

Code: Select all

*mediaPath = Ascii("yourmediafile.mp4")
media = CallFunction(lib, "libvlc_media_new_path", vlcInst, *mediaPath)
Don't forget to use FreeMemory(*mediaPath) when you close the file.
macOS Catalina 10.15.7
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Trying libvlc VLC Player

Post by Justin »

It does not work, i think is a problem of the virtual machine, is a know problem it seems. VLC Player itself does not work either.
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Trying libvlc VLC Player

Post by Wolfram »

How does you "yourmediafile.mp4" look?
It should look like "/Users/yourName/Desktop/yourMovie.mp4"
If the path is wrong I get an blank Window too.
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Trying libvlc VLC Player

Post by wilbert »

It works on my iMac but it does seem to give problems when the media path contains spaces. :?
And a CanvasGadget isn't required. A ContainerGadget works just as well.
Windows (x64)
Raspberry Pi OS (Arm64)
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Trying libvlc VLC Player

Post by Justin »

There is an issue with the encoding, only if I use ascii or utf8 I can get the media duration but the video still does not play. It seems virtual box does not support playing video on OS X there is some info if you google it.
This gets the correct duration, maybe someone could test it on PB 5.60.

Code: Select all

mediapathi = Ascii("/Users/name/Documents/video.avi") ;or utf8
media = CallFunction(lib, "libvlc_media_new_path", vlcInst, mediaPathi)
Debug media
CallFunction(lib, "libvlc_media_parse", media)
Debug "dur"
Debug CallFunction(lib, "libvlc_media_get_duration", media)
Thanks.
Post Reply