Platforms to show: All Mac Windows Linux Cross-Platform
/AVFoundation/AVAssetExportSessionMBS test batch
Required plugins for this example: MBS MacOSX Plugin, MBS MacClassic Plugin, MBS AVFoundation Plugin, MBS Util 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 batch
This example is the version from Fri, 23th May 2013.
Project "AVAssetExportSessionMBS test batch.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."
quit
end if
AVFoudation = new MyAVFoudationMBS
// select videos
dim folder as FolderItem = SpecialFolder.desktop.Child("test")
if folder.Exists = false then
MsgBox "Please put test folder on desktop with videos for batch export."
Return
end if
dim c as integer = folder.Count
for i as integer = 1 to c
dim file as FolderItem = folder.Item(i)
Export file
next
AutoQuit = true
End EventHandler
Sub Export(file as FolderItem)
dim a as AVAssetMBS = AVAssetMBS.assetWithFile(file)
if a = nil then
MsgBox "This is not a video/audio file."+EndOfLine+file.UnixpathMBS
quit
end if
dim e as new AVAssetExportSessionMBS(a, AVAssetExportSessionMBS.AVAssetExportPreset640x480)
e.timeRange = CMTimeRangeMBS.AllTimeRange
e.shouldOptimizeForNetworkUse = true
dim extension as string = e.outputFileType
dim filetypes() as string = e.supportedFileTypes
e.outputFileType = FileTypes(0)
dim outputfile as FolderItem = SpecialFolder.Desktop.Child(file.NameWithoutExtensionMBS+"."+e.outputFileExtension)
if OutputFile.Exists then
MoveFileToTrash OutputFile
OutputFile = SpecialFolder.Desktop.Child(file.NameWithoutExtensionMBS+"."+e.outputFileExtension)
end if
e.OutputFile = OutputFile
System.DebugLog outputfile.UnixpathMBS
dim pw as new ProgressWindow
pw.e = e
pw.a = a
pw.outputfile = outputfile
pw.show
e.exportAsynchronously(pw)
End Sub
Sub MoveFileToTrash(f as FolderItem)
dim r as FolderItem
call MacFileOperationMBS.MoveObjectToTrashSync(f, r, MacFileOperationMBS.kFSFileOperationDefaultOptions)
End Sub
Property AVFoudation 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()
if e<>nil then
bar.Value = e.progress * bar.Maximum
status.text = Format(e.progress,"0%")+" done"
end if
End EventHandler
End Control
Control Status Inherits Label
ControlInstance Status Inherits Label
End Control
EventHandler Function CancelClose(appQuitting as Boolean) As Boolean
if e<>Nil then
e.cancelExport
end if
End EventHandler
Property a As AVAssetMBS
Property e As AVAssetExportSessionMBS
Property outputfile As FolderItem
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)
dim pw as ProgressWindow = tag
pw.e = nil
pw.a = nil
if pw.Status = nil then Return // window already closed
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
pw.Status.text = "Export done."
case ExportSession.AVAssetExportSessionStatusFailed
pw.Status.text = "Export failed."
case ExportSession.AVAssetExportSessionStatusCancelled
pw.Status.text = "Export cancelled."
end Select
if ExportSession.error <> Nil then
pw.Status.text = "Error: "+ExportSession.error.localizedDescription
end if
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS AVFoundation Plugin.