VLC + PureBasic

Windows specific forum
deano1987
User
User
Posts: 19
Joined: Thu Jul 30, 2009 11:39 pm
Location: england, cannock, west midlands

VLC + PureBasic

Post by deano1987 »

Hey guys, I'm newish when it comes to calling DLL's into an application AND new to the VLC DLL Documentation.

I'm trying to run VLC into my PB window and so far I have been successful, I can load, stop and load another movie using the VLC API... But what I want to do is next is get the media length so I can show a progress bar!!

Here is my code so far, make sure you download VLC 0.9.6 as this is not compatible with the latest VLC (Todo after I get this working)

Thanks, and I hope you can take some time out to help me learn more PB and this API :)

You can view some API documentation on VLC here: http://vlc.sourcearchive.com/documentat ... /main.html

Make sure you change the location path AND the VLC location path to your 0.9.6 path.

Code: Select all

;   v windows
;   v linux
;   x macosx
;     - opengl won't open, sometimes ascii caca output is selected:
;       "no opengl provider module matching "default" could be loaded"

; struct
; Using VLC 0.9.6 perhaps I can improve this!
Structure mediacontrol_Instance
  *p_instance;
  *p_media_player;
EndStructure
Structure libvlc_exception
    raised.l
    code.l
    message.s
EndStructure
Structure libvlc_log_message_t
  sizeof_msg.l
  i_severity.i
  *psz_type.s
  *psz_name.s
  *psz_header.s
  *psz_message.s
EndStructure

Structure mediacontrol_info
  length.i
  position.i
  *stream
  *url.s
EndStructure

; global vars
Global Dim vlc_args.s(10)

; OS Specific..
CompilerSelect #PB_Compiler_OS
   CompilerCase #PB_OS_Linux
      Structure _GdkScreen Extends GdkScreen ; PB def seems to be incomplete
        *font_options;
        resolution.d
      EndStructure
      Structure GdkScreenX11
        parent_instance._GdkScreen;
        *display;
        *xdisplay;
        *xscreen;
      EndStructure
      Structure GdkDrawableImplX11
        parent_instance.GdkDrawable
        *wrapper;
        *colormap;
        xid.l
        *screen
         picture.l ;Picture
        *cairo_surface;
      EndStructure
       Structure _GdkWindowObject ; PB def is empty!
        parent_instance.GdkDrawable;
        *impl.GdkDrawable
        *parent;
        user_data.l
      EndStructure
      Procedure XDisplayFromWindowID(*Window.GtkWidget)
        *gdkwindowobj._GdkWindowObject = *Window\window
        *impl.GdkDrawableImplX11 = *gdkwindowobj\impl
        *screen.GdkScreenX11 = *impl\screen
        ProcedureReturn *impl\xid ;*screen\xdisplay       
      EndProcedure 
CompilerEndSelect

; procedures
Procedure Debug_Exception(cmd.s,ex.l,result.l=-1)
   If ex
     *exception.libvlc_exception=ex
     If *exception\raised 
        Debug "Debug_Exception"
        Debug cmd+" = "+Str(result)
        Debug "libvlc_exception\raised="+Str(*exception\raised)
        Debug "libvlc_exception\code="+Str(*exception\code)
        Debug "libvlc_exception\message="+*exception\message
        Debug " "
     EndIf
   EndIf
EndProcedure
Procedure.l getosdrawable()
   drawable.l = 0
   CompilerSelect #PB_Compiler_OS
     CompilerCase #PB_OS_Linux
       drawable=XDisplayFromWindowID(WindowID(0))
     CompilerCase #PB_OS_Windows
       drawable=WindowID(0)
     CompilerCase #PB_OS_MacOS
       drawable=GetWindowPort_(WindowID(0))
   CompilerEndSelect
   ProcedureReturn drawable
EndProcedure
Procedure.s getoslib()
   lib$ = ""
   CompilerSelect #PB_Compiler_OS
     CompilerCase #PB_OS_Linux
       lib$ = "/usr/lib/libvlc.so"
     CompilerCase #PB_OS_Windows
       lib$ = "C:\Program Files\VideoLAN\VLC\libvlc.dll"
     CompilerCase #PB_OS_MacOS
       lib$ = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib"
   CompilerEndSelect   
   ProcedureReturn lib$
EndProcedure
Procedure.l setosarguments()
  vlc_args(0) = "-I"
  vlc_args(1) = "dummy"
  vlc_args(2) = "--ignore-config"
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    vlc_args(3) = "--plugin-path=/usr/lib/vlc/codecs/"
  CompilerEndIf     
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    vlc_args(3) = "--plugin-path=C:\\Program Files\\VideoLAN\\VLC\\plugins\\"
  CompilerEndIf     
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    vlc_args(3) = "--plugin-path=/Applications/VLC.app/Contents/MacOS/modules/"
  CompilerEndIf
  vlc_args(4) = "--mms-caching"
  vlc_args(5) = "3200"
  vlc_args(6) = "--http-caching"
  vlc_args(7) = "3200"
EndProcedure

; local vars
lib$                                  = getoslib()
*mediacontrol.mediacontrol_Instance   = 0
*inst                                 = 0
ex.l                                  = 0
wevent.l                              = 0
width.l                               = 0
height.l                              = 0
owidth.l                              = 0
oheight.l                             = 0
*log                                  = 0
logcount.l                            = 0
count.l                               = 0
*it                                   = 0
pos.f                                 = 0
*media.mediacontrol_info  = 0

; Choose any media file..
location.s                            = "C:\Users\dean.williams\dwhelper\Culture Club - Karma Chameleon.mp4"
location2.s                            = "C:\Users\dean.williams\dwhelper\Bloodhound Gang - The Bad Touch.mp4"

; main
SetCurrentDirectory(GetPathPart(lib$))
If OpenLibrary(0, lib$)   
   If OpenWindow(0, 0, 0, 320,200, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget) 
      SmartWindowRefresh(0, 0) ;: SetWindowColor(0, RGB(0,0,0))
      draw = getosdrawable()
      setosarguments()

      CallCFunction(0, "libvlc_exception_init", @ex):
      ;Debug_Exception("libvlc_exception_init", @ex)

      *inst = CallCFunction(0, "libvlc_new", 8,@vlc_args(),@ex)
      ;Debug_Exception("libvlc_new", @ex)

      *log = CallCFunction(0, "libvlc_log_open", *inst, @ex)
      ;Debug_Exception("libvlc_log_open", @ex)
           
      CallCFunction(0, "libvlc_set_log_verbosity", *log, 10000, @ex)
      ;Debug_Exception("libvlc_set_log_verbosity", @ex)
                 
      If *inst And *log
         CallCFunction(0, "libvlc_video_set_parent", *inst, draw, @ex)
         ;Debug_Exception("libvlc_video_set_parent", @ex)

         *mediacontrol.mediacontrol_Instance = CallCFunction(0, "mediacontrol_new_from_instance", *inst, @ex)
         ;Debug_Exception("mediacontrol_new_from_instance", @ex)

         CallCFunction(0, "mediacontrol_set_mrl", *mediacontrol, location.s, @ex )         
         ;Debug_Exception("mediacontrol_set_mrl", @ex)

         CallCFunction(0, "mediacontrol_start", *mediacontrol, @pos.f, @ex )
         ;Debug_Exception("mediacontrol_start", @ex)

         If OpenWindow(1, 0, 0, 320,200, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget) 
            ButtonGadget(1, 10, 10, 200, 20, "Click me")
            TrackBarGadget(2, 10, 10, 300, 20, 0, 100)
            
         EndIf
         
         If *mediacontrol.mediacontrol_Instance
            Repeat
               wevent = WindowEvent(): Delay(10)             
               
                *media = CallCFunction(0, "mediacontrol_get_stream_information", *mediacontrol   , @ex )
                Debug *media\length
                ;SetGadgetAttribute(2,#PB_TrackBar_Maximum,)
               
               Select wevent
     
                 Case #PB_Event_Gadget
                   Select EventGadget()
                     Case 1
                        Debug "Button Pushed"
                        ;CallCFunction(0, "mediacontrol_stop", *mediacontrol, @ex )
                        ;CallCFunction(0, "libvlc_release", *inst)
                        ;CallCFunction(0, "libvlc_log_close", *log)
                        CallCFunction(0, "mediacontrol_set_rate", *mediacontrol, "1", @ex )
                        ;CallCFunction(0, "mediacontrol_set_mrl", *mediacontrol, location2.s, @ex )
                        ;CallCFunction(0, "mediacontrol_start", *mediacontrol, @pos.f, @ex )
                        
                     Case 2 : Debug "Button 2 clicked!"
                     Case 3 : Debug "Button 3 clicked!"
                   EndSelect
                   
               EndSelect

            Until wevent = #PB_Event_CloseWindow
         EndIf               
         CallCFunction(0, "libvlc_release", *inst)
         ;CallCFunction(0, "libvlc_log_close", *log)
      EndIf
      CloseWindow(0)
   EndIf
   CloseLibrary(0)
EndIf
End
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Re: VLC + PureBasic

Post by oryaaaaa »

VLC 1.1.11.1

I didn't run this tips.

Code: Select all

      *mediacontrol.mediacontrol_Instance = CallCFunction(0, "mediacontrol_new_from_instance", *inst, @ex)
Always, retrurn 0. WindowsXP SP3 JP.
deano1987
User
User
Posts: 19
Joined: Thu Jul 30, 2009 11:39 pm
Location: england, cannock, west midlands

Re: VLC + PureBasic

Post by deano1987 »

oryaaaaa wrote:VLC 1.1.11.1

I didn't run this tips.

Code: Select all

      *mediacontrol.mediacontrol_Instance = CallCFunction(0, "mediacontrol_new_from_instance", *inst, @ex)
Always, retrurn 0. WindowsXP SP3 JP.
Like I said you have to use VLC 0.9.6.

I have gone for a Java implementation as there is a great package available for accessing VLC (and it works with the latest version), and there's far more support (PB seems to be dead these days).

Java 1 - Purebasic 0
Post Reply