Page 1 of 1

Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 11:19 am
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

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 1:31 pm
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).

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 4:29 pm
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?

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 5:31 pm
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.

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 5:45 pm
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.

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 5:57 pm
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.

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 7:28 pm
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.

Re: Trying libvlc VLC Player

Posted: Sun Sep 10, 2017 7:36 pm
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.