Platforms to show: All Mac Windows Linux Cross-Platform
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 two videos
This example is the version from Sat, 15th Mar 2024.
Project "Show two videos.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
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 = GetFolderItem("/Applications/VLC.app", folderitem.PathTypeNative)
#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
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
#if RBVersion < 2013 then
self.Refresh(False)
#else
self.invalidate
#endif
end if
end if
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()
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 "--verbose=0" // show only errors */
margs.append "--no-media-library" // don't want that */
margs.append "--no-sub-autodetect" // don't want subtitles */
margs.append "--ignore-config"
System.DebugLog "Init..."
v = 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
#if RBVersion < 2013 then
m = VLCMediaMBS.MediaWithPath(v, Moviefile.UnixpathMBS)
#else
m = VLCMediaMBS.MediaWithPath(v, Moviefile.NativePath)
#endif
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
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
System.DebugLog "VideoSetCallback..."
timer1.Mode = timer.ModeMultiple
mp.VideoSetCallback w, h
call mp.Play
PlaybackWindow1.show
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()
dim p as Double = mp.Position
mp.stop
System.DebugLog "VideoSetCallback..."
'#if TargetMacOS then
'// install callbacks to draw video into CGContextMBS object.
'dim c as CGContextMBS = me.CGContextMBS
'self.CGContext = c
'
'mp.VideoSetCallback(width, height, c.Handle)
'#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
Property v As VLCInstanceMBS
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
Class PlaybackWindow1 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
#if RBVersion < 2013 then
self.Refresh(False)
#else
self.invalidate
#endif
end if
end if
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()
dim moviefile as FolderItem = SpecialFolder.Desktop.Child("test.m4v")
if moviefile.Exists = false then
MsgBox "Please put test.mov on your desktop or change path in code."
Return
end if
v = PlaybackWindow.v
// and simply play a movie. Video goes to our buffer, so we can get it in the timer
#if RBVersion < 2013 then
m = VLCMediaMBS.MediaWithPath(v, Moviefile.UnixpathMBS)
#else
m = VLCMediaMBS.MediaWithPath(v, Moviefile.NativePath)
#endif
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
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
System.DebugLog "VideoSetCallback..."
timer1.Mode = timer.ModeMultiple
mp.VideoSetCallback w, h
call mp.Play
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()
dim p as Double = mp.Position
mp.stop
System.DebugLog "VideoSetCallback..."
'#if TargetMacOS then
'// install callbacks to draw video into CGContextMBS object.
'dim c as CGContextMBS = me.CGContextMBS
'self.CGContext = c
'
'mp.VideoSetCallback(width, height, c.Handle)
'#else
timer1.Mode = timer.ModeMultiple
mp.VideoSetCallback width, height
'#endif
call mp.Play
mp.Position = p
End EventHandler
Property CGContext As Variant
Property Counter As Integer
Property CurrentPicture As Picture
Property m As VLCMediaMBS
Property mp As VLCMediaPlayerMBS
Property v As VLCInstanceMBS
End Class
Sign
End Sign
End Project
See also:
The items on this page are in the following plugins: MBS VLC Plugin.