Platforms to show: All Mac Windows Linux Cross-Platform
/AVFoundation/AVAssetExportSessionMBS test
Required plugins for this example: MBS AVFoundation Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS Main Plugin, MBS MacBase Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /AVFoundation/AVAssetExportSessionMBS test
This example is the version from Thu, 26th Nov 2014.
Project "AVAssetExportSessionMBS test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
if AVAssetExportSessionMBS.available = false then
MsgBox "Please run on Mac OS X 10.7 or newer."
quit
end if
// select a video
dim file as FolderItem = GetOpenFolderItem("")
if file = nil then quit
f = new MyAVFoudationMBS
dim a as AVAssetMBS = AVAssetMBS.assetWithFile(file)
if a = nil then
MsgBox "This is not a video/audio file."
quit
end if
SettingsWindow.a = a
SettingsWindow.show
AutoQuit = true
End EventHandler
Property f As MyAVFoudationMBS
End Class
Class ProgressWindow Inherits Window
Control bar Inherits ProgressBar
ControlInstance bar Inherits ProgressBar
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
bar.Value = e.progress * bar.Maximum
End EventHandler
End Control
EventHandler Function CancelClose(appQuitting as Boolean) As Boolean
if e<>Nil then
e.cancelExport
end if
End EventHandler
Property e As AVAssetExportSessionMBS
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 MyAVFoudationMBS Inherits AVFoundationMBS
EventHandler Sub exportAsynchronouslyCompleted(ExportSession as AVAssetExportSessionMBS, tag as variant)
ProgressWindow.close
Select case ExportSession.status
case ExportSession.AVAssetExportSessionStatusUnknown
break
case ExportSession.AVAssetExportSessionStatusWaiting
break // should never happen
case ExportSession.AVAssetExportSessionStatusExporting
break // should never happen
case ExportSession.AVAssetExportSessionStatusCompleted
MsgBox "Export done."
case ExportSession.AVAssetExportSessionStatusFailed
MsgBox "Export failed."
case ExportSession.AVAssetExportSessionStatusCancelled
MsgBox "Export cancelled."
end Select
if ExportSession.error <>Nil then
MsgBox "Error: "+ExportSession.error.localizedDescription
end if
End EventHandler
End Class
Class SettingsWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change()
RunButton.Enabled = me.ListIndex >= 0
End EventHandler
End Control
Control RunButton Inherits PushButton
ControlInstance RunButton Inherits PushButton
EventHandler Sub Action()
run
End EventHandler
End Control
Control CheckNetwork Inherits CheckBox
ControlInstance CheckNetwork Inherits CheckBox
End Control
EventHandler Sub Open()
dim presets() as string = AVAssetExportSessionMBS.exportPresetsCompatibleWithAsset(a)
if presets.IndexOf(AVAssetExportSessionMBS.AVAssetExportPresetPassthrough) = -1 then
presets.Append AVAssetExportSessionMBS.AVAssetExportPresetPassthrough
end if
for each s as string in presets
List.AddRow s
next
End EventHandler
Sub Run()
dim e as new AVAssetExportSessionMBS(a, list.Cell(list.ListIndex,0))
e.timeRange = CMTimeRangeMBS.AllTimeRange
e.shouldOptimizeForNetworkUse = CheckNetwork.Value
dim extension as string = e.outputFileType
dim filetypes() as string = e.supportedFileTypes
e.outputFileType = FileTypes(0)
e.OutputFile = SpecialFolder.Desktop.Child("test."+e.outputFileExtension)
ProgressWindow.e = e
ProgressWindow.show
e.exportAsynchronously(nil)
close
End Sub
Property a As AVAssetMBS
End Class
End Project
See also:
The items on this page are in the following plugins: MBS AVFoundation Plugin.