Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacCF Plugin, MBS MacBase Plugin, MBS MacOSX Plugin, MBS MacClassic Plugin, MBS Picture Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/DVD/DVD Playback2
This example is the version from Sun, 5th Nov 2022.
Project "DVD Playback2.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Last Inherits Label
ControlInstance Last Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean
dim i as integer
I=d.DoMenuClick(x,y)
CheckLastError "DoMenuClick"
End EventHandler
EventHandler Sub MouseMove(X As Integer, Y As Integer)
dim i as integer
i=d.DoMenuMouseOver(x,y)
CheckLastError "DoMenuMouseOver"
End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control pos Inherits Label
ControlInstance pos Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
d.Play
CheckLastError "Play"
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
d.Pause
CheckLastError "Pause"
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
d.NextChapter
CheckLastError "NextChapter"
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
d.PreviousChapter
CheckLastError "PreviousChapter"
End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action()
dim w,p as Picture
w=ScreenshotRectMBS(left+Canvas1.Left,top+Canvas1.top, Canvas1.Width,Canvas1.Height)
p = new Picture(Canvas2.Width,Canvas2.Height,32)
p.Graphics.DrawPicture w,0,0,p.Width,p.Height,0,0,w.width,w.height
Canvas2.Backdrop=p
End EventHandler
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action()
if theDVD<>nil then
d.Stop
CheckLastError "Stop"
d.CloseMediaVolume
CheckLastError "CloseMediaVolume"
if not d.IsPlaying then
dim e as integer = theDVD.UnMountVolumeMBS
if e<>0 then
MsgBox "unmount error"
end if
end if
end if
End EventHandler
End Control
EventHandler Sub Close()
if mediaOpened then
d.CloseMediaVolume
end if
End EventHandler
EventHandler Function KeyDown(Key As String) As Boolean
if key=" " then
UpdatePosition
Return true
end if
End EventHandler
EventHandler Sub Open()
Init
End EventHandler
EventHandler Sub Resized()
d.SetVideoBounds 0,0,Canvas1.Width,Canvas1.Height
CheckLastError "SetVideoBounds"
End EventHandler
Sub CheckLastError(s as string)
if d.Lasterror<>0 then
last.text=s+" failed with error "+str(d.Lasterror)+": "+d.LasterrorString
end if
'MsgBox s
End Sub
Sub Init()
dim v,dvd as FolderItem
dim i,c as integer
d=new MyDVDPlayback
d.Open
CheckLastError "Open"
if d.Lasterror=0 then
c=VolumeCount-1
for i=1 to c
v=volume(i)
if d.IsValidMedia(v) then
dvd=v
end if
next
if dvd=nil then
MsgBox "No DVD media found."
else
dim w as NSWindowMBS = self.NSWindowMBS
d.SetVideoWindowID(w.windowNumber)
'd.SetPlayWindow(self,0)
CheckLastError "SetPlayWindow"
if d.Lasterror=0 then
d.SetVideoBounds 0,0,Canvas1.Width,Canvas1.Height
CheckLastError "SetVideoBounds"
if d.Lasterror=0 then
d.OpenMediaVolume dvd
CheckLastError "OpenMediaVolume"
if d.Lasterror=0 then
theDVD=dvd
mediaOpened=true
d.play
CheckLastError "Play"
end if
end if
end if
end if
else
MsgBox "Only one application on Mac OS X 10.3 can play a DVD."
end if
End Sub
Sub OpenVolume(v as folderitem)
if not d.IsPlaying then
if d.IsValidMedia(v) then
'd.SetPlayWindow(self,0)
'CheckLastError "SetPlayWindow"
if d.Lasterror=0 then
d.SetVideoBounds 0,0,Canvas1.Width,Canvas1.Height
CheckLastError "SetVideoBounds"
if d.Lasterror=0 then
d.OpenMediaVolume v
CheckLastError "OpenMediaVolume"
if d.Lasterror=0 then
theDVD=v
mediaOpened=true
d.play
CheckLastError "Play"
end if
end if
end if
end if
end if
End Sub
Sub UpdatePosition()
const kDVDTimeCodeUninitialized = 0
const kDVDTimeCodeElapsedSeconds = 1
const kDVDTimeCodeRemainingSeconds = 2
const kDVDTimeCodeTitleDurationSeconds = 3 // only useable for GetTime
const kDVDTimeCodeChapterElapsedSeconds = 4 // "
const kDVDTimeCodeChapterRemainingSeconds = 5 // "
const kDVDTimeCodeChapterDurationSeconds = 6 // "
dim p as string
dim title as integer
dim t,f as integer
dim Elapsed as integer
dim Duration as integer
title=d.GetTitle
p="Title "+str(title)+" of "+str(d.GetNumberOfTitles)
p=p+", Chapter "+str(d.GetChapter)+" of "+str(d.GetNumberOfChapters(title))
d.GetTime(kDVDTimeCodeElapsedSeconds, t, f)
Elapsed=t
d.GetTime(kDVDTimeCodeTitleDurationSeconds, t, f)
Duration=t
p=p+", Time: "+formattime(Elapsed)+" of "+formattime(Duration)
if pos.text<>p then
pos.text=p
end if
End Sub
Function formattime(i as integer) As String
dim second, minute, hour as integer
dim n as integer
n=i
second=n mod 60
n=n-second
n=n\60
minute=n mod 60
n=n-minute
n=n\60
hour=n
if hour=0 then
Return Format(minute,"00")+":"+Format(second,"00")
else
Return Format(hour,"0")+":"+Format(minute,"00")+":"+Format(second,"00")
end if
End Function
Property Protected d As MyDVDPlayback
Property Protected inmenu As boolean
Property Protected mediaOpened As boolean
Property theDVD As folderitem
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
// found volume mount event
c=new MyCarbonApplicationEventsMBS
c.Listen
End EventHandler
Property c As mycarbonApplicationEventsMBS
End Class
Class MyDVDPlayback Inherits DVDPlaybackMBS
EventHandler Sub DVDEvent(eventcode as integer, value1 as integer, value2 as integer)
// you may do something here...
'mainWindow.Title=str(eventcode)
MainWindow.UpdatePosition
End EventHandler
EventHandler Sub FatalError(errorcode as integer)
MsgBox "Fatal error "+str(errorcode)+" in the DVD Playback Framework!"
quit
End EventHandler
End Class
Class MyCarbonApplicationEventsMBS Inherits CarbonApplicationEventsMBS
EventHandler Sub VolumeMounted(VolumeRefNum as integer, VolumeRoot as FolderItem)
Dim i,c As Integer
dim v as FolderItem
dim found as Boolean
// search folderiten for VolumeRefNum
found=False
c=VolumeCount-1
for i=0 to c
v=Volume(i)
#If RBVersion < 2020 Then
If v.MacVRefNum=VolumeRefNum Then
found=True
Exit
End If
#EndIf
If v.DarwinMediaClassMBS = "IODVDMedia" Then
found=True
Exit
End If
next
if found then
MainWindow.OpenVolume v
end if
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacOSX Plugin.