Platforms to show: All Mac Windows Linux Cross-Platform

/VLC/Play audio


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/Play audio

This example is the version from Sat, 15th Mar 2024.

Project "Play audio.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 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() mp.Pause End EventHandler
End Control
Control VolumeSlider Inherits Slider
ControlInstance VolumeSlider Inherits Slider
EventHandler Sub ValueChanged() mp.Volume = me.Value LabelVolume.Text = str(me.Value) End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control LabelVolume Inherits Label
ControlInstance LabelVolume Inherits Label
End Control
Control PositionSlider Inherits Slider
ControlInstance PositionSlider Inherits Slider
EventHandler Sub ValueChanged() if NoEvents then Return // ignore mp.Position = me.Value / 1000.0 Labelposition.Text = str(me.Value * mp.Length / 1000000.0, "0.0") End EventHandler
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Labelposition Inherits Label
ControlInstance Labelposition Inherits Label
End Control
Control StatusTimer Inherits Timer
ControlInstance StatusTimer Inherits Timer
EventHandler Sub Action() NoEvents = true if mp <> nil then PositionSlider.Value = mp.Position * 1000.0 Labelposition.Text = str(mp.Position * mp.Length / 1000.0, "0.0") end if Finally NoEvents = false 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.mp3") if moviefile.Exists = false then MsgBox "Please put test.mp3 on your desktop or change path in code." Return end if dim LibName as string = kLibrary 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 if s.LoadDylib(libvlccore9.NativePath) 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 if s.LoadDylib(libvlccore8.NativePath) 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 if s.LoadDylib(libvlc5.NativePath) then 'MsgBox "OK" LibName = libvlc5.NativePath 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") System.EnvironmentVariable("VLC_PLUGIN_PATH") = Plugins.NativePath #endif // 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" ' margs.Append "--no-plugins-cache" // maybe no cache? System.DebugLog "Init..." 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 mp.Volume = 50 call mp.Play End EventHandler
Property Counter As Integer
Property NoEvents As Boolean
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
Sign
End Sign
End Project

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


The biggest plugin in space...