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.