Video Player based on VLC

Windows specific forum
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Philippe-felixer76-2 wrote:
Inner wrote:http://rainbowplayer.googlecode.com/fil ... alpha3.zip
Procedure PBVLC_MakeArgs(array Array.s(1), num, array newarr(1))
i = 0
Repeat
newarr(i) = AllocateMemory(StringByteLength(Array(i))+1)
PokeS(newarr(i), Array(i), -1, #PB_UTF8)
i+1
Until i>=num
EndProcedure
Don't like that much you'd offen memory if you forgot to clear your "AllocateMemory(StringByteLength(Array(i))+1)" and fragment it over time.
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

Inner wrote:
Philippe-felixer76-2 wrote:
Inner wrote:http://rainbowplayer.googlecode.com/fil ... alpha3.zip
Procedure PBVLC_MakeArgs(array Array.s(1), num, array newarr(1))
i = 0
Repeat
newarr(i) = AllocateMemory(StringByteLength(Array(i))+1)
PokeS(newarr(i), Array(i), -1, #PB_UTF8)
i+1
Until i>=num
EndProcedure
Don't like that much you'd offen memory if you forgot to clear your "AllocateMemory(StringByteLength(Array(i))+1)" and fragment it over time.
I was more trying to make clear that linux uses (array Array.s(1)) in the procedure and windows just (Array.s(1)).

But your right, must be a better way arround it. I will try to make
your source all fit into one source file, this is more easy to trace
any problems. And i found a lot of them :( Ill post later on..
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

Philippe-felixer76-2 wrote:Yeah but before i call ImportC is do a setcurrentdirectory() to
VLC. So the program directory should be good
nope, windows tries to load the dll before ANYTHING of the exe get executed, so the 'current directory' would be either the exe's dir, or whatever the shortcut set it to, or in the case of debugger execution, whatever PB sets it to.

yeah, PB runs - it just needs xcode (like the docs say) 2.5 for 10.4 and 3.0 for 10.5 i believe.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

Philippe-felixer76-2 wrote: But your right, must be a better way arround it. I will try to make
your source all fit into one source file, this is more easy to trace
any problems. And i found a lot of them :( Ill post later on..
I call it a day for now.. :P

I worked on the libvlc_example.pb file, and i fixed some
stuff and added some stuff.

It now uses libvlc mediacontrol API commands. Works very
good on windows, not tested in linux yet.

Code: Select all

;*****************************************************************************
; Example: pbvlc.pb
; By: T.J.Roughton
; Requires: libvlc.pb (includes)
;*****************************************************************************
IncludeFile "libvlc.pb"

Structure mediacontrol_Instance 
  *p_instance;
  *p_media_player;
EndStructure

Structure mediacontrol_stream_information
   streamstatus.l
   url.s
   position.q
   length.q
EndStructure

Structure MediaControl_Position
   *origin ;mediacontrol_PositionOrigin origin;
   *key ;mediacontrol_PositionKey key;
   value.q ;int64_t value;
EndStructure 

mediacontrol_ByteCount   = 0
mediacontrol_SampleCount = 1
mediacontrol_MediaTime   = 2
;mediacontrol_PositionKey 

mediacontrol_AbsolutePosition = 0
mediacontrol_RelativePosition = 1
mediacontrol_ModuloPosition   = 2
;mediacontrol_PositionOrigin

Enumeration
  #WINDOW_PLAYMEDIA
EndEnumeration

Enumeration
  #GAD_TRACKBAR
  #GAD_FILE
  #GAD_PLAYPAUSE
  #GAD_MEDIACONTAINER
EndEnumeration

Global Dim vlc_args.s(8)
Global Dim utf8args(8)
Global instants.l, mplayer.l

;*****************************************************************************
; VLC Exception
;*****************************************************************************
Procedure Debug_Exception(cmd.s,ex.l,result.l=-1)
  *exception.libvlc_exception=ex
  OpenConsole()
    PrintN(cmd+" = "+Str(result))
    PrintN("libvlc_exception\raised="+Str(*exception\raised))
    PrintN("libvlc_exception\code="+Str(*exception\code))
    PrintN("libvlc_exception\message="+*exception\message)
  CloseConsole()
EndProcedure

;*****************************************************************************
; Choose URL/File
;*****************************************************************************
Procedure.s OpenWindow_ChooseURLFILE()
  result.s=""
  If OpenWindow(1, 0, 0, 300, 50, "Choose URL/File", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
    ButtonGadget(5,10,10,135,30,"URL")
    ButtonGadget(6,155,10,135,30,"FILE")
    While wevent<>#PB_Event_CloseWindow
      wevent = WindowEvent()  
      If wevent = #PB_Event_Gadget
        Select EventGadget()
          Case 5 ; URL
            result.s=InputRequester("URL","Enter URL","")
            wevent=#PB_Event_CloseWindow
          Case 6 ; FILE
            result.s=OpenFileRequester("File","","",0)
            wevent=#PB_Event_CloseWindow
        EndSelect
      EndIf
    Wend
  EndIf
  CloseWindow(1)
  ProcedureReturn result
EndProcedure

;*****************************************************************************
; Set Args
;*****************************************************************************
Procedure SetArguments(location.s)
  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     
  vlc_args(4) = "--mms-caching"
  vlc_args(5) = "3200"
  vlc_args(6) = "--http-caching"
  vlc_args(7) = "3200" 
  PBVLC_MakeArgs(vlc_args(), 8, utf8args())
EndProcedure

;*****************************************************************************
; Load a file or URL
;*****************************************************************************
Procedure loadmedia(in.s)
    mediacontrol = mediacontrol_new_from_instance(instants, @exception )
    mediacontrol_set_mrl(mediacontrol, in.s, @exception )
    mediacontrol_start( mediacontrol, @pos.f, @exception )
    ProcedureReturn mediacontrol
EndProcedure

Procedure displaytext(*mediacontrol, text.s)         
   *start.mediacontrol_position = mediacontrol_get_media_position(*mediacontrol, 0, 2, @exception)
   *eind.mediacontrol_position  = mediacontrol_get_media_position(*mediacontrol, 0, 2, @exception)
   mediacontrol_display_text( *mediacontrol, text.s, @*start, @*eind, @exception );
EndProcedure

;*****************************************************************************
; Roll it!
;*****************************************************************************
Procedure OpenWindow_PlayMedia(location.s)
  exception.libvlc_exception


  If OpenWindow(#WINDOW_PLAYMEDIA, 0, 0, 60, 20, "PureBasic VLC", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
    ButtonGadget(#GAD_FILE, 0, 0, 0, 0, "F")
    ButtonGadget(#GAD_PLAYPAUSE, 0, 0, 0, 0, ">")
    ScrollBarGadget(#GAD_TRACKBAR, 0, 0, 0, 0, 0, 1000, 1)
    ContainerGadget(#GAD_MEDIACONTAINER, 0, 0, 0, 0)    

    ; Get a drawable window dependant on which os the source was compiled on.
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Linux
        drawable=PBVLC_XDisplayFromWindowID(GadgetID(#GAD_MEDIACONTAINER))
      CompilerCase #PB_OS_Windows
        drawable=GadgetID(#GAD_MEDIACONTAINER)
      CompilerCase #PB_OS_MacOS
        drawable=GadgetID(#GAD_MEDIACONTAINER)
    CompilerEndSelect
    
    ; Set the arguments up for VLC
    SetArguments(location)
    ; Init
    libvlc_exception_init(@exception)
    instants = libvlc_new (8,@utf8args(),@exception)            
    
    ; we must start playing so that libvlc_video_set_parent has some input first! 
    libvlc_video_set_parent (instants,drawable,@exception) 
   
    ; load media
    *mediacontrol.mediacontrol_Instance  = loadmedia(location.s)
    
       
    oldwsize.l=0
    oldhsize.l=0
    oldcurpos.q=0
    
    While wevent<>#PB_Event_CloseWindow
      wevent = WindowEvent()  
      If wevent = 13104 ; from fullscreen back to normal window..
         SetActiveWindow(#WINDOW_PLAYMEDIA)
      EndIf
      If wevent = #PB_Event_Gadget
        Select EventGadget()
          Case #GAD_TRACKBAR
             If *mediacontrol
                *info.mediacontrol_stream_information = mediacontrol_get_stream_information( *mediacontrol, "0", @exception )
                pos.mediacontrol_position
                pos\value  = GetGadgetState(#GAD_TRACKBAR)*(*info\length/1000)
                pos\origin = 0
                pos\key    = 2
                mediacontrol_set_media_position(*mediacontrol, pos, @exception )
             EndIf
          Case #GAD_FILE
             *mediacontrol.mediacontrol_Instance  = loadmedia(OpenWindow_ChooseURLFILE())
          Case #GAD_PLAYPAUSE
             If *mediacontrol
                 mediacontrol_pause( *mediacontrol, @exception )
                 If GetGadgetText(#GAD_PLAYPAUSE) = ">"
                    SetGadgetText(#GAD_PLAYPAUSE, "||")                  
                 Else
                    SetGadgetText(#GAD_PLAYPAUSE, ">")
                 EndIf        
             EndIf  
          Case #GAD_MEDIACONTAINER
        EndSelect
      EndIf
      If wevent=#PB_Event_SizeWindow
        If IsGadget(#GAD_TRACKBAR)
          ResizeGadget(#GAD_TRACKBAR, 40, WindowHeight(#WINDOW_PLAYMEDIA)-20, WindowWidth(#WINDOW_PLAYMEDIA)-40, 20)
        EndIf
        If IsGadget(#GAD_FILE)
          ResizeGadget(#GAD_FILE, 0, WindowHeight(#WINDOW_PLAYMEDIA)-20, 20, 20)
        EndIf
        If IsGadget(#GAD_PLAYPAUSE)
          ResizeGadget(#GAD_PLAYPAUSE, 20, WindowHeight(#WINDOW_PLAYMEDIA)-20, 20, 20)
        EndIf
        If IsGadget(#GAD_MEDIACONTAINER)
          ResizeGadget(#GAD_MEDIACONTAINER, 0, 0, WindowWidth(#WINDOW_PLAYMEDIA), WindowHeight(#WINDOW_PLAYMEDIA)-20)
        EndIf
        ;displaytext(*mediacontrol, "RESIZE WINDOW") 
      EndIf
      
      If *mediacontrol     
          *info.mediacontrol_stream_information = 0
          *info.mediacontrol_stream_information = mediacontrol_get_stream_information( *mediacontrol, "0", @exception )
          Select *info\streamstatus
            Case 0 ; libvlc_NothingSpecial    
            Case 1 ; libvlc_Opening    
            Case 2 ; libvlc_Buffering    
            Case 3 ; libvlc_Playing
              width=libvlc_video_get_width(*mediacontrol\p_media_player,@exception)
              height=libvlc_video_get_height(*mediacontrol\p_media_player,@exception)
              If (width<>oldwsize And height<>oldhsize)
                oldwsize=width
                oldhsize=height
                ResizeWindow(#WINDOW_PLAYMEDIA,#PB_Ignore,#PB_Ignore,width,height+20)
                length.q=*info\length ;libvlc_media_player_get_length(*mediacontrol\p_media_player,@exception)
                stukje.q=length.q/1000
                If length=0
                  DisableGadget(#GAD_TRACKBAR,1)
                Else
                  DisableGadget(#GAD_TRACKBAR,0)
                EndIf
                SetGadgetText(#GAD_PLAYPAUSE, "||")                             
              EndIf
              curpos.q=libvlc_media_player_get_time(*mediacontrol\p_media_player,@exception)
              If curpos<>curposo          
                 curposo=curpos
                 stukje.q = length / 1000
                 If (stukje>0 And curpos>0)
                  SetGadgetState(#GAD_TRACKBAR,curpos/stukje)
                 EndIf
              EndIf
              ;displaytext(*mediacontrol, "") 
            Case 4 ; libvlc_Paused   
            Case 5 ; libvlc_Stopped   
            Case 6 ; libvlc_Forward    
            Case 7 ; libvlc_Backward    
            Case 8 ; libvlc_Ended    
            Case 9 ; libvlc_Error
          EndSelect
      EndIf
      Delay(1)
    Wend  
    If *mediacontrol
       mediacontrol_exit(*mediacontrol)
    EndIf
    libvlc_release(instants)
    CloseWindow(#WINDOW_PLAYMEDIA)
  EndIf
EndProcedure
;-----------------------------------------------------------------------------
OpenWindow_PlayMedia(OpenWindow_ChooseURLFILE())
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

lexvictory wrote:
Philippe-felixer76-2 wrote:Yeah but before i call ImportC is do a setcurrentdirectory() to
VLC. So the program directory should be good
nope, windows tries to load the dll before ANYTHING of the exe get executed, so the 'current directory' would be either the exe's dir, or whatever the shortcut set it to, or in the case of debugger execution, whatever PB sets it to.

yeah, PB runs - it just needs xcode (like the docs say) 2.5 for 10.4 and 3.0 for 10.5 i believe.
Ok, tnx for the info!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

some unicode fixes: (I compile all my programs in unicode mode)

line 64 of libvlc_pbaddons.pb SHOULD read

Code: Select all

newarr(i) = AllocateMemory(StringByteLength(Array(i), #PB_UTF8)+1)
otherwise twice the memory required is allocated in unicode mode (the whole reason the procedure is there)

to not allocate memory and then 'forget' about it, add this to libvlc_pbaddons:

Code: Select all

Procedure PBVLC_FreeArgs(Array utf8array(1))
  num = ArraySize(utf8array())
  i=0
  Repeat 
    If utf8array(i)
      FreeMemory(utf8array(i))
    EndIf
    i+1
  Until i=num 
EndProcedure
then in libvlc_example.pb after the call of libvlc_release()
add a line that says

Code: Select all

PBVLC_FreeArgs(utf8args())
also, on all the files that use importc, do a search and replace for .s replacing with .p-utf8

then it works in unicode mode.

ideally you should also be copying the vlc plugins dir to the source's dir, along with libvlc.dll and libvlccore.dll - i had to change some paths because my vlc dir is h:\program files (x86)\videolan\...
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

http://rainbowplayer.googlecode.com/fil ... alpha5.zip

Alpha v0.4
Completed: mediacontrol_structures.pb was missing a few structures.
Added: pbvlc_example2.pb - an example of using mediacontrol api.
Added: Structure mediacontrol_Instance To libvlc_pbaddons.pb (probably shouldn't be here)
Added: history.txt

Alpha v0.5
Added: PBVLC_FreeArgs() To libvlc_pbaddons.pb
Fixed: PBVLC_MakeArgs() UTF8 Bug.
Fixed: UTF8 in libvlc_linux.pb , libvlc_macos.pb & libvlc_windows.pb

(sorry about that would have made the 0.5 changes to 0.4 didn't see the above post before it was already uploaded, and posted)
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

Inner wrote:http://rainbowplayer.googlecode.com/fil ... alpha5.zip

Alpha v0.4
Completed: mediacontrol_structures.pb was missing a few structures.
Added: pbvlc_example2.pb - an example of using mediacontrol api.
Added: Structure mediacontrol_Instance To libvlc_pbaddons.pb (probably shouldn't be here)
Added: history.txt

Alpha v0.5
Added: PBVLC_FreeArgs() To libvlc_pbaddons.pb
Fixed: PBVLC_MakeArgs() UTF8 Bug.
Fixed: UTF8 in libvlc_linux.pb , libvlc_macos.pb & libvlc_windows.pb

(sorry about that would have made the 0.5 changes to 0.4 didn't see the above post before it was already uploaded, and posted)
Nice one!

I added some fixes and stuff:
- pbvlc_example2
- stop old video when selected another one
- plugin path for windows using win32 api, detect system path etc..
- libvlc_windows.pb
- get the global program files dir.
- genertate a .lib file out of the libvlc.dll using polib
- setcurrent directory to vlc
- add VLC directory to the system search dll PATH

I still need to set the directory to VLC in compiler options ;-(
And if i don't, i get a new error, quit unexpectedly instead of
can't find libvlc.dll.

It seems to work very stable now on windows.

pbvlc_example2:

Code: Select all

;*****************************************************************************
; Example: pbvlc_example2.pb
; By: T.J.Roughton & Philippe Felixer
; Requires: libvlc.pb (includes)
;*****************************************************************************

IncludeFile "libvlc.pb"

Enumeration
  #WINDOW_PLAYMEDIA
EndEnumeration

Enumeration
  #GAD_TRACKBAR
  #GAD_FILE
  #GAD_PLAYPAUSE
  #GAD_MEDIACONTAINER
EndEnumeration

Global Dim vlc_args.s(8)
Global Dim utf8args(8)
Global instants.l ;, mplayer.l

;*****************************************************************************
; VLC Exception
;*****************************************************************************
Procedure Debug_Exception(cmd.s,ex.l,result.l=-1)
  *exception.libvlc_exception=ex
  OpenConsole()
    PrintN(cmd+" = "+Str(result))
    PrintN("libvlc_exception\raised="+Str(*exception\raised))
    PrintN("libvlc_exception\code="+Str(*exception\code))
    PrintN("libvlc_exception\message="+*exception\message)
  CloseConsole()
EndProcedure

;*****************************************************************************
; Choose URL/File
;*****************************************************************************
Procedure.s OpenWindow_ChooseURLFILE()
  result.s=""
  If OpenWindow(1, 0, 0, 300, 50, "Choose URL/File", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
    ButtonGadget(5,10,10,135,30,"URL")
    ButtonGadget(6,155,10,135,30,"FILE")
    While wevent<>#PB_Event_CloseWindow
      wevent = WindowEvent() 
      If wevent = #PB_Event_Gadget
        Select EventGadget()
          Case 5 ; URL
            result.s=InputRequester("URL","Enter URL","")
            wevent=#PB_Event_CloseWindow
          Case 6 ; FILE
            result.s=OpenFileRequester("File","","",0)
            wevent=#PB_Event_CloseWindow
        EndSelect
      EndIf
    Wend
  EndIf
  CloseWindow(1)
  ProcedureReturn result
EndProcedure

;*****************************************************************************
; Set Args
;*****************************************************************************
Procedure SetArguments()
  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
    dir.s = win32dir.s + "\VideoLAN\VLC\plugins"
    dir.s = ReplaceString(dir.s, "", "\")
    vlc_args(3) = "--plugin-path="+dir.s 
  CompilerEndIf     
  vlc_args(4) = "--mms-caching"
  vlc_args(5) = "3200"
  vlc_args(6) = "--http-caching"
  vlc_args(7) = "3200"
  PBVLC_MakeArgs(vlc_args(), 8, utf8args())
EndProcedure

;*****************************************************************************
; Load a file or URL
;*****************************************************************************
Procedure loadmedia(in.s)
    mediacontrol = mediacontrol_new_from_instance(instants, @exception )
    mediacontrol_set_mrl(mediacontrol, in.s, @exception )
    mediacontrol_start( mediacontrol, @pos.f, @exception )
    ProcedureReturn mediacontrol
EndProcedure

;*****************************************************************************
; Display Text on Video
;*****************************************************************************
Procedure displaytext(*mediacontrol, text.s)         
   *start.mediacontrol_position = mediacontrol_get_media_position(*mediacontrol, 0, 2, @exception)
   *eind.mediacontrol_position  = mediacontrol_get_media_position(*mediacontrol, 0, 2, @exception)
   mediacontrol_display_text( *mediacontrol, text.s, @*start, @*eind, @exception );
EndProcedure

;*****************************************************************************
; Roll it!
;*****************************************************************************
Procedure OpenWindow_PlayMedia(location.s)
  exception.libvlc_exception

  If OpenWindow(#WINDOW_PLAYMEDIA, 0, 0, 60, 20, "PureBasic VLC", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
    ButtonGadget(#GAD_FILE, 0, 0, 0, 0, "F")
    ButtonGadget(#GAD_PLAYPAUSE, 0, 0, 0, 0, ">")
    ScrollBarGadget(#GAD_TRACKBAR, 0, 0, 0, 0, 0, 1000, 1)
    ContainerGadget(#GAD_MEDIACONTAINER, 0, 0, 0, 0)   

    ; Get a drawable window dependant on which os the source was compiled on.
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Linux
        drawable=PBVLC_XDisplayFromWindowID(GadgetID(#GAD_MEDIACONTAINER))
      CompilerCase #PB_OS_Windows
        drawable=GadgetID(#GAD_MEDIACONTAINER)
      CompilerCase #PB_OS_MacOS
        drawable=GadgetID(#GAD_MEDIACONTAINER)
    CompilerEndSelect
   
    ; Set the arguments up for VLC
    SetArguments()
    
    ; Init
    libvlc_exception_init(@exception)
    instants = libvlc_new (8,@utf8args(),@exception)           
   
    ; set the drawable before starting to play
    libvlc_video_set_parent (instants,drawable,@exception)
   
    ; load media
    *mediacontrol.mediacontrol_Instance  = loadmedia(location.s)
          
    oldwsize.l=0
    oldhsize.l=0
    oldcurpos.q=0
   
    While wevent<>#PB_Event_CloseWindow
      wevent = WindowEvent() 
      If wevent = 13104 ; from fullscreen back to normal window..
         SetActiveWindow(#WINDOW_PLAYMEDIA)
      EndIf
      If wevent = #PB_Event_Gadget
        Select EventGadget()
          Case #GAD_TRACKBAR
             If *mediacontrol
                *info.mediacontrol_StreamInformation = mediacontrol_get_stream_information( *mediacontrol, "0", @exception )
                pos.mediacontrol_position
                pos\value  = GetGadgetState(#GAD_TRACKBAR)*(*info\length/1000)
                pos\origin = 0
                pos\key    = 2
                mediacontrol_set_media_position(*mediacontrol, pos, @exception )
             EndIf
          Case #GAD_FILE
             If *mediacontrol 
                 mediacontrol_stop(*mediacontrol, @exception)
                 mediacontrol_exit(*mediacontrol)
             EndIf             
             *mediacontrol.mediacontrol_Instance  = loadmedia(OpenWindow_ChooseURLFILE())
          Case #GAD_PLAYPAUSE
             If *mediacontrol
                 mediacontrol_pause( *mediacontrol, @exception )
                 If GetGadgetText(#GAD_PLAYPAUSE) = ">"
                    SetGadgetText(#GAD_PLAYPAUSE, "||")                 
                 Else
                    SetGadgetText(#GAD_PLAYPAUSE, ">")
                 EndIf       
             EndIf 
          Case #GAD_MEDIACONTAINER
        EndSelect
      EndIf
      If wevent=#PB_Event_SizeWindow
        If IsGadget(#GAD_TRACKBAR)
          ResizeGadget(#GAD_TRACKBAR, 40, WindowHeight(#WINDOW_PLAYMEDIA)-20, WindowWidth(#WINDOW_PLAYMEDIA)-40, 20)
        EndIf
        If IsGadget(#GAD_FILE)
          ResizeGadget(#GAD_FILE, 0, WindowHeight(#WINDOW_PLAYMEDIA)-20, 20, 20)
        EndIf
        If IsGadget(#GAD_PLAYPAUSE)
          ResizeGadget(#GAD_PLAYPAUSE, 20, WindowHeight(#WINDOW_PLAYMEDIA)-20, 20, 20)
        EndIf
        If IsGadget(#GAD_MEDIACONTAINER)
          ResizeGadget(#GAD_MEDIACONTAINER, 0, 0, WindowWidth(#WINDOW_PLAYMEDIA), WindowHeight(#WINDOW_PLAYMEDIA)-20)
        EndIf
      EndIf
     
      If *mediacontrol     
          *info.mediacontrol_StreamInformation = 0
          *info.mediacontrol_StreamInformation = mediacontrol_get_stream_information( *mediacontrol, "0", @exception )
          Select *info\streamstatus
            Case 0 ; libvlc_NothingSpecial   
            Case 1 ; libvlc_Opening   
            Case 2 ; libvlc_Buffering   
            Case 3 ; libvlc_Playing
              width=libvlc_video_get_width(*mediacontrol\mediaplayer,@exception)
              height=libvlc_video_get_height(*mediacontrol\mediaplayer,@exception)
              If (width<>oldwsize And height<>oldhsize)
                If *info\url
                   If GetWindowTitle(#WINDOW_PLAYMEDIA)<>*info\url
                      SetWindowTitle(#WINDOW_PLAYMEDIA, *info\url)
                   EndIf
                EndIf
                oldwsize=width
                oldhsize=height
                ResizeWindow(#WINDOW_PLAYMEDIA,#PB_Ignore,#PB_Ignore,width,height+20)
                length.q=*info\length
                stukje.q=length.q/1000
                If length=0
                  DisableGadget(#GAD_TRACKBAR,1)
                Else
                  DisableGadget(#GAD_TRACKBAR,0)
                EndIf
                SetGadgetText(#GAD_PLAYPAUSE, "||")                             
              EndIf
              curpos.q=libvlc_media_player_get_time(*mediacontrol\mediaplayer,@exception)
              If curpos<>curposo         
                 curposo=curpos
                 stukje.q = length / 1000
                 If (stukje>0 And curpos>0)
                  SetGadgetState(#GAD_TRACKBAR,curpos/stukje)
                 EndIf
              EndIf
            Case 4 ; libvlc_Paused   
            Case 5 ; libvlc_Stopped   
            Case 6 ; libvlc_Forward   
            Case 7 ; libvlc_Backward   
            Case 8 ; libvlc_Ended   
            Case 9 ; libvlc_Error
          EndSelect
      EndIf
      Delay(1)
    Wend 
    If *mediacontrol
       mediacontrol_exit(*mediacontrol)
    EndIf
    libvlc_release(instants)
    CloseWindow(#WINDOW_PLAYMEDIA)
  EndIf
EndProcedure
;-----------------------------------------------------------------------------
OpenWindow_PlayMedia(OpenWindow_ChooseURLFILE()) 
pbvlc_windows.pb:

Code: Select all

;/*****************************************************************************
; * libvlc.h:  libvlc external API
; *****************************************************************************
; * Copyright (C) 1998-2005 the VideoLAN team
; * $Id$
; *
; * Authors: Clément Stenac <zorglub@videolan.org>
; *          Jean-Paul Saman <jpsaman@videolan.org>
; *          Pierre d'Herbemont <pdherbemont@videolan.org>
; *
; * This program is free software; you can redistribute it and/or modify
; * it under the terms of the GNU General Public License as published by
; * the Free Software Foundation; either version 2 of the License, or
; * (at your option) any later version.
; *
; * This program is distributed in the hope that it will be useful,
; * but WITHOUT ANY WARRANTY; without even the implied warranty of
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; * GNU General Public License for more details.
; *
; * You should have received a copy of the GNU General Public License
; * along with this program; if not, write to the Free Software
; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
; *****************************************************************************/

; 
; DO NOT REMOVE COMMENTS PLEASE, FOR SOME THERE THE ONLY WAY TO DEBUG THE CONVERSION
; IF IT IS IN ERROR, AND DISCOVER HOW THIS API WORKS!
;

Global win32dir.s

Procedure.s SpecialFolder(folderno)
  listptr=0
  result$=Space(270)
  SHGetSpecialFolderLocation_(0,folderno,@listptr)
  SHGetPathFromIDList_(listptr,@result$)
  ProcedureReturn Trim(result$)
EndProcedure

; Generate libvlc.lib file
win32dir.s = SpecialFolder(#CSIDL_PROGRAM_FILES)
If FileSize(win32dir.s+"\VideoLAN\VLC\libvlc.lib")<1
   If FileSize(win32dir.s+"\VideoLAN\VLC\libvlc.dll")>0
      sfile.s = win32dir.s+"\VideoLAN\VLC\libvlc.dll"
      dfile.s = win32dir.s+"\VideoLAN\VLC\libvlc.lib"
      cmd.s   = "polib.exe"
      If FileSize(sfile.s)>0 And FileSize(win32dir.s+"\PureBasic\Compilers"+cmd.s)>0
         RunProgram(cmd.s, "/out:"+Chr(34)+dfile.s+Chr(34)+" "+Chr(34)+sfile.s+Chr(34), win32dir.s+"\PureBasic\Compilers" )
         RunProgram(cmd.s, "/out:"+Chr(34)+GetCurrentDirectory()+"libvlc.lib"+Chr(34)+" "+Chr(34)+sfile.s+Chr(34), win32dir.s+"\PureBasic\Compilers" )
         If FileSize(sfile.s)<1
            MessageRequester("Error", "Creating libvlc.lib file!"): End
         EndIf
      Else
         MessageRequester("Error", "Purebasic not found!"): End
      EndIf
   Else
      MessageRequester("Error", "Couldn't find libvlc.dll"): End   
   EndIf
EndIf

; Setcurrent directory to VLC
SetCurrentDirectory(win32dir.s+"\VideoLAN\VLC") 

; Add VLC dir (DLL Path) to systemdir..
Lib_Kernel32 = OpenLibrary(#PB_Any,"Kernel32.dll")
*SetDllDirectory = GetFunction(Lib_Kernel32,"SetDllDirectoryA")
 If *SetDllDirectory <> 0
  String.s = win32dir.s+"\VideoLAN\VLC" ;GetCurrentDirectory()
  result = CallFunctionFast(*SetDllDirectory,@String)
  If result =0
    Debug Str(GetLastError_())
  EndIf
EndIf
CloseLibrary(Lib_Kernel32)


;"C:\Program Files\VideoLAN\VLC")
ImportC  "libvlc.lib"
......REST OF THE CODE IS THE SAME AS OLD VERSION.... 
Gr,
Phil.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

http://rainbowplayer.googlecode.com/fil ... alpha6.zip

Alpha v0.6
Added: Windows functionality functions To libvlc_pbaddons.pb

note: I didn't put your procedures etc. in libvlc_windows.pb but in libvlc_pbaddons, as this functionality has nothing to do with libvlc directly, libvlc_pbaddons.pb is just to make life easier using it.

And I didn't test it either has I don't have windows, well I don't have a functional windows with all the right software installed :) it's purpose is boot, load teamspeak, play virtual skipper 5, until wine supports it properly then windows dies utterly on these PCs.
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

On Windows, when compiling finishes it claims that libvlc.dll cant be found.
The .lib file has been genrated correctly in the VLC dir.
Check out OOP support for PB here!
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

inc. wrote:On Windows, when compiling finishes it claims that libvlc.dll cant be found.
The .lib file has been genrated correctly in the VLC dir.
You need to set the directory in compiler options to VLC. I know..
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

LIBVLC OSX Progress

Post by Philippe-felixer76-2 »

LibVLC for OSX:

http://nightlies.videolan.org/build/mac ... 8-0100.zip

Think libvlc_macos.pb needs:

Code: Select all

ImportC "/VLCKit.framework/lib/libvlc.dylib"
(Assuming it's installed on the main HD like this..)

And i think the setarguments() needs:

Code: Select all

CompilerIF #PB_Compiler_OS = #PB_OS_MacOS
   vlc_args(3) = "--plugin-path=/VLCKit.framework/modules/"
CompilerEndIf
But, i don's get it to work, i get the following messages:

; pbvlc_example1.pb
Image

;pbvlc_example2.pb
Image

I use OSX 10.5 and xcodec3, kind of a bummer :)

UPDATE: Found this:

http://www.purebasic.fr/english/viewtop ... ed+symbols

Not supported i ques..
Philippe-felixer76-2
Enthusiast
Enthusiast
Posts: 135
Joined: Sat Aug 18, 2007 7:09 am
Location: Netherlands

Post by Philippe-felixer76-2 »

Inner wrote:And I didn't test it either has I don't have windows, well I don't have a functional windows with all the right software installed :) it's purpose is boot, load teamspeak, play virtual skipper 5, until wine supports it properly then windows dies utterly on these PCs.
QEMU ?! :-P
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Re: LIBVLC OSX Progress

Post by lexvictory »

Philippe-felixer76-2 wrote:UPDATE: Found this:

http://www.purebasic.fr/english/viewtop ... ed+symbols

Not supported i ques..
I think that is to do with making a dylib. not 100% sure though.
I'll have a look at it later today, as it looks just like the import functions need a bit of tweaking - similar to what I got on debian etch - which only has libvlc 0.8 or something I think.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Re: LIBVLC OSX Progress

Post by lexvictory »

Philippe-felixer76-2 wrote:LibVLC for OSX:

http://nightlies.videolan.org/build/mac ... 8-0100.zip
mac os 10.4.8's linker doesnt like those libs at all, says they're invalid.

I'll (try) compile the lib. Just got to find the instructions again :lol:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply