Why some dylib's are inaccessible?

Mac OSX specific forum
Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Why some dylib's are inaccessible?

Post by Lebostein »

For example the VLC lib. With PB 5.7x and VLC 3.0.8 it worked without problems (I build a small VLC-video player with PureBasic and the lib). But with newer PB versions and/or newer VLC versions it don't work:

Code: Select all

Debug OpenLibrary(0, "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib")
I get always zero...
Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Re: Why some dylib's are inaccessible?

Post by Lebostein »

OK, this drives me crazy. Here is an example code, that plays a movie in a PureBasic-Window with the VLC-Lib.

What you need is:
1. An installed VLC.app in Applications folder (x64, for example the current version 3.0.20) -> https://www.videolan.org/vlc/index.de.html
2. Any video in your download directory (customize "path_to_movie$" in code!)

My test enviroments (result is the same)
* macOS Catalina 10.15.7 with 5.73 LTS (MacOS X - x64) .... 6.10 beta 1 - C Backend (MacOS X - x64)
* macOS Ventura 13.6.1 with 6.04 LTS - C Backend (MacOS X - x64) .... 6.10 beta 1 - C Backend (MacOS X - x64)
and different versions between

The code works only, if I load and unload an old VLC-Lib from version 3.0.9.1 before (at the moment you can only download 3.0.9.2 from VLC, but it seems work only with the 3.0.9.1)! I don't understand why. For testing I could offer this old lib (160 kb).

Code: Select all

; successfully tested with
; 10.15.7 (Catalina)
;   + PureBasic 5.73 LTS (MacOS X - x64)
;   + PureBasic 6.00 Beta 6 (MacOS X - x64)
;   + PureBasic 6.10 beta 1 - C Backend (MacOS X - x64)
; 13.6.1 (Ventura)
;   + PureBasic 6.04 LTS - C Backend (MacOS X - x64)
;   + PureBasic 6.10 beta 1 - C Backend (MacOS X - x64)

; ***** workaround start (the code only works if you have previously open and close the old 3.0.9.1 lib, why I don't know)
test = OpenLibrary(#PB_Any, "libvlc.5.dylib") ; old lib from 3.0.9.1, md5 = 333726e7271377f34fa2746e21564d75, file date = 08.03.2020
CloseLibrary(test)
; ***** workaround end

path_to_movie$ = GetUserDirectory(#PB_Directory_Downloads) + "testmovie.mp4"

SetEnvironmentVariable("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins/") ; path to VLC installation
libvlc_main = OpenLibrary(#PB_Any, "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib") ; path to VLC installation

If libvlc_main

  PrototypeC.i p_libvlc_new(argc.i, argv.p-utf8)
  libvlc_new.p_libvlc_new = GetFunction(libvlc_main, "libvlc_new")

  PrototypeC.i p_libvlc_media_player_new(*p_instance)
  libvlc_media_player_new.p_libvlc_media_player_new = GetFunction(libvlc_main, "libvlc_media_player_new")

  PrototypeC.i p_libvlc_media_player_set_nsobject(*p_mi, *drawable)
  libvlc_media_player_set_nsobject.p_libvlc_media_player_set_nsobject = GetFunction(libvlc_main, "libvlc_media_player_set_nsobject")

  PrototypeC.i p_libvlc_media_new_path(*p_instance, path.p-utf8)
  libvlc_media_new_path.p_libvlc_media_new_path = GetFunction(libvlc_main, "libvlc_media_new_path")

  PrototypeC.i p_libvlc_media_player_set_media(*p_mi, *p_md)
  libvlc_media_player_set_media.p_libvlc_media_player_set_media = GetFunction(libvlc_main, "libvlc_media_player_set_media")

  PrototypeC.i p_libvlc_media_player_play(*p_mi)
  libvlc_media_player_play.p_libvlc_media_player_play = GetFunction(libvlc_main, "libvlc_media_player_play")

Else

  MessageRequester("Error", "lib not opened!", #PB_MessageRequester_Error)
  End

EndIf

; --- start program

OpenWindow(0, 100, 100, 960, 540, "VLC Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0, 0, 0, WindowWidth(0), WindowHeight(0)): CloseGadgetList()

inst = libvlc_new(0, #Null$)
player = libvlc_media_player_new(inst)
libvlc_media_player_set_nsobject(player, GadgetID(0))
media = libvlc_media_new_path(inst, path_to_movie$)
libvlc_media_player_set_media(player, media)
libvlc_media_player_play(player)

Repeat: event = WaitWindowEvent(20)
Until event = #PB_Event_CloseWindow
Post Reply