Platforms to show: All Mac Windows Linux Cross-Platform
/AVFoundation/AVAudioPlayer Loop
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/AVAudioPlayer Loop
This example is the version from Tue, 24th Sep 2018.
Project "AVAudioPlayer Loop.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
MyAVFoundation = new MyAVFoundationMBS
log "Load audio..."
AddPlayer "/System/Library/Sounds/Hero.aiff"
AddPlayer "/System/Library/Sounds/Submarine.aiff"
AddPlayer "/System/Library/Sounds/Glass.aiff"
dim p1 as AVAudioPlayerMBS = Players(0)
log "Play "+p1.Name
if p1.play then
// okay
else
// failed to play
break
end if
End EventHandler
Sub AddPlayer(f as FolderItem)
dim e as NSErrorMBS
dim p as AVAudioPlayerMBS = AVAudioPlayerMBS.audioPlayerWithFile(f, e)
if e <> nil then
MsgBox e.LocalizedDescription
end if
if p = nil then
// failed to load?
break
return
end if
players.Append p
End Sub
Sub AddPlayer(path as string)
dim f as FolderItem
#if RBVersion > 2013 then
f = GetFolderItem(path, FolderItem.PathTypeNative)
#else
f = GetFolderItem(path, FolderItem.PathTypeShell)
#endif
AddPlayer f
End Sub
Property Shared MyAVFoundation As MyAVFoundationMBS
Property Shared Players() As AVAudioPlayerMBS
End Class
Class LogWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyAVFoundationMBS Inherits AVFoundationMBS
EventHandler Sub audioPlayerDidFinishPlaying(player as AVAudioPlayerMBS, successful as boolean)
if successful then
log "Player "+player.name+" is done successfully."
else
log "Player "+player.name+" is done with problem."
end if
dim Players() as AVAudioPlayerMBS = app.Players
dim u as integer = Players.Ubound
// index of current one
dim i as integer = players.IndexOf(player)
// index of next one
dim n as integer = i + 1
if n > u then
n = 0
end if
dim p as AVAudioPlayerMBS = players(n)
log "Play " + p.Name
call p.play
End EventHandler
End Class
Module Module1
Sub Log(s as string)
dim l as listbox = LogWindow.List
l.AddRow s
l.ScrollPosition = l.ListCount
End Sub
End Module
End Project
The items on this page are in the following plugins: MBS AVFoundation Plugin.