Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/VLC/Show video sample
Required plugins for this example: MBS VLC Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /VLC/Show video sample
This example is the version from Thu, 30th Jan 2019.
Project "Show video sample.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // this example runs on Mac in 32 and 64 bit with VLC 2.0.9 libraries // it does currently not work for VLC 3.0 as initialization fails DebugCopyLibs End EventHandler
Sub DebugCopyLibs() // copy vlc libs into app // you need 32 bit version of VLC to have this work for 32bit app! // and 64-bit libs for 64-bit app #if TargetMacOS then #if Target32Bit then // we keep an old copy of version 2.0.9 for 32-bit dim apppath as FolderItem = SpecialFolder.Applications.Child("VLC alt.app") #else dim apppath as FolderItem = SpecialFolder.Applications.Child("VLC.app") #endif if apppath<>Nil and apppath.Visible then dim ContentsFolder as FolderItem = apppath.Child("Contents") if ContentsFolder<>Nil and ContentsFolder.Visible then dim MacOSFolder as FolderItem = ContentsFolder.Child("MacOS") if MacOSFolder<>Nil and MacOSFolder.Visible then dim TargetFolder as FolderItem = app.ExecutableFile.parent dim LibFolder as FolderItem = MacOSFolder.Child("lib") LibFolder.CopyFileTo TargetFolder dim pluginsFolder as FolderItem = MacOSFolder.Child("plugins") pluginsFolder.CopyFileTo TargetFolder end if end if end if #endif #if TargetWin32 then dim VideoLANFolder as FolderItem = SpecialFolder.Applications.Child("VideoLAN") if VideoLANFolder<>Nil and VideoLANFolder.Visible then System.DebugLog VideoLANFolder.NativePath dim VLCFolder as FolderItem = VideoLANFolder.Child("VLC") if VLCFolder<>Nil and VLCFolder.Exists then dim ExecutableFolder as FolderItem = app.ExecutableFile.parent dim libvlc as FolderItem = VLCFolder.Child("libvlc.dll") libvlc.CopyFileTo ExecutableFolder dim libvlccore as FolderItem = VLCFolder.Child("libvlccore.dll") libvlccore.CopyFileTo ExecutableFolder dim pluginsFolder as FolderItem = VLCFolder.Child("plugins") dim destPluginsFolder as FolderItem = ExecutableFolder.Child("plugins") // copy whole folder dim w as new WindowsFileCopyMBS call w.FileOperationCopy(pluginsFolder, destPluginsFolder, w.FileOperationNoErrorUI+w.FileOperationNoConfirmation) end if end if #endif #if TargetLinux // please copy libs or put symlinks in the folder now Break #endif End Sub
Note "PluginsNeeded"
This examples needs: * MBS Xojo VLC Plugin * MBS Xojo Main Plugin * MBS Xojo MacCG Plugin for CGContextMBS * MBS Xojo MacBase Plugin * MBS Xojo MacCloud Plugin for NSFileManager * MBS Xojo MacCF Plugin for MacCG * MBS Xojo Util Plugin for SoftDeclareMBS
End Class
Class PlaybackWindow Inherits Window
Const kLibrary = "libvlc"
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if mp<>Nil then if mp.HasNewFrame then // show frame counter Counter = Counter + 1 Title = Str(Counter) // and draw picture to window CurrentPicture = mp.CopyPicture 'Graphics.DrawPicture CurrentPicture,0,0 #if RBVersion < 2013 then self.Refresh(False) #else self.invalidate #endif end if end if End EventHandler
End Control
Control OutputCanvas Inherits Canvas
ControlInstance OutputCanvas Inherits Canvas
End Control
Control PlayButton Inherits PushButton
ControlInstance PlayButton Inherits PushButton
EventHandler Sub Action() call mp.Play End EventHandler
End Control
Control PauseButton Inherits PushButton
ControlInstance PauseButton Inherits PushButton
EventHandler Sub Action() call mp.Pause End EventHandler
End Control
EventHandler Function CancelClose(appQuitting as Boolean) As Boolean if mp<>Nil then mp.stop end if End EventHandler
EventHandler Sub Open() 'System.DebugLog CurrentMethodName dim moviefile as FolderItem = SpecialFolder.Desktop.Child("test.mov") if moviefile.Exists = false then MsgBox "Please put test.mov on your desktop or change path in code." Return end if dim LibName as string = kLibrary InitForMacOS LibName // load library if VLCInstanceMBS.LoadLibrary(LibName) then System.DebugLog "Library Loaded." else msgbox "Failed to load library"+EndOfLine+EndOfLine+VLCInstanceMBS.GetLoadError Return end if // startup vlc engine dim margs(-1) as string margs.append "--no-video-title-show" // nor the filename displayed */ margs.append "--no-media-library" // don't want that */ margs.append "--no-sub-autodetect" // don't want subtitles */ margs.append "--ignore-config" 'margs.Append "--no-plugins-cache" // maybe no cache? 'margs.append "--verbose=2" // show only errors */ System.DebugLog "Init..." for each arg as string in margs System.DebugLog arg next dim v as new VLCInstanceMBS(margs) System.DebugLog "Inited." if v.Handle=0 then msgbox "Failed to initialise." Return end if // and simply play a movie. Video goes to our buffer, so we can get it in the timer m = VLCMediaMBS.MediaWithFile(v, Moviefile) if m = nil then MsgBox "Failed to get media." Return end if System.DebugLog "Init MediaPlayer..." mp = new VLCMediaPlayerMBS(m) if mp.Handle=0 then msgbox "Failed to init media player." Return end if // figure out size of video System.DebugLog "Parse..." m.Parse System.DebugLog "TrackInfos..." dim info() as VLCMediaTrackInfoMBS = m.TrackInfos // scale window ? dim h as integer = 640 dim w as integer = 480 for each i as VLCMediaTrackInfoMBS in info if i.Type = i.TrackVideo then System.DebugLog "Video track with: "+str(i.Width)+" x "+str(i.Height) w = i.Width h = i.Height end if next Width = w Height = h + 52 // alternative way without views, but getting pictures 'System.DebugLog "VideoSetCallback..." 'timer1.Mode = timer.ModeMultiple 'mp.VideoSetCallback w, h // directly to the NSView #if TargetMacOS then mp.NSObject = Ptr(OutputCanvas.Handle) #elseif TargetWin32 then mp.HWND = OutputCanvas.Handle #elseif TargetLinux then mp.XWindow = OutputCanvas.Handle #endif End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) if CurrentPicture <> nil then g.DrawPicture CurrentPicture, 0, 0, g.Width, g.Height, 0, 0, CurrentPicture.Width, CurrentPicture.Height end if End EventHandler
EventHandler Sub Resized() // only for timer mode with pictures... 'dim p as Double = mp.Position 'mp.stop ' 'System.DebugLog "VideoSetCallback..." '#if TargetMacOS then '// install callbacks to draw video into CGContextMBS object. 'mp.VideoSetCallback(width, height) '#else 'timer1.Mode = timer.ModeMultiple 'mp.VideoSetCallback width, height '#endif ' 'call mp.Play 'mp.Position = p End EventHandler
Sub InitForMacOS(byref LibName as string) dim ExecutableFolder as FolderItem = app.ExecutableFile.parent #if TargetMacOS then // preload library, so it's not complaining that file is not found later. dim LibFolder as FolderItem = ExecutableFolder.Child("lib") dim libvlccore9 as FolderItem = LibFolder.Child("libvlccore.9.dylib") if libvlccore9 <> nil and libvlccore9.Exists then dim s as new SoftDeclareMBS dim p as string #if RBVersion < 2013 then p = libvlccore9.UnixpathMBS #else p = libvlccore9.NativePath #endif if s.LoadDylib(p) then 'MsgBox "OK" System.DebugLog libvlccore9.name+" loaded." else MsgBox s.Liberror end if end if dim libvlccore8 as FolderItem = LibFolder.Child("libvlccore.8.dylib") if libvlccore8 <> nil and libvlccore8.Exists then dim s as new SoftDeclareMBS dim p as string #if RBVersion < 2013 then p = libvlccore8.UnixpathMBS #else p = libvlccore8.NativePath #endif if s.LoadDylib(p) then 'MsgBox "OK" System.DebugLog libvlccore8.name+" loaded." else MsgBox s.Liberror end if end if dim libvlc5 as FolderItem = LibFolder.Child("libvlc.5.dylib") if libvlc5 <> nil and libvlc5.Exists then dim s as new SoftDeclareMBS dim p as string #if RBVersion < 2013 then p = libvlc5.UnixpathMBS #else p = libvlc5.NativePath #endif if s.LoadDylib(p) then 'MsgBox "OK" LibName = p System.DebugLog libvlc5.name+" loaded." else MsgBox s.Liberror end if end if // we need to put path to plugins in environment variable to make it work dim Plugins as FolderItem = ExecutableFolder.Child("plugins") dim p as string #if RBVersion < 2013 then p = Plugins.UnixpathMBS #else p = Plugins.NativePath #endif System.EnvironmentVariable("VLC_PLUGIN_PATH") = p #endif End Sub
Property CGContext As Variant
Property Counter As Integer
Property CurrentPicture As Picture
Property m As VLCMediaMBS
Property mp As VLCMediaPlayerMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS VLC Plugin.

The biggest plugin in space...

MBS Xojo Plugins