Platforms to show: All Mac Windows Linux Cross-Platform
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/AudioPlayer
This example is the version from Mon, 7th Jul 2013.
Project "AudioPlayer.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action()
dim f as FolderItem = GetOpenFolderItem(FileTypes1.All)
if f = nil then Return
dim e as NSErrorMBS
player = new AVAudioPlayerMBS(f, e)
if e<>Nil then
MsgBox e.LocalizedDescription
else
player.meteringEnabled = true
end if
End EventHandler
End Control
Control BevelButton2 Inherits BevelButton
ControlInstance BevelButton2 Inherits BevelButton
EventHandler Sub Action()
if player.play then
// ok
else
MsgBox "failed to play."
end if
End EventHandler
End Control
Control BevelButton3 Inherits BevelButton
ControlInstance BevelButton3 Inherits BevelButton
EventHandler Sub Action()
player.pause
End EventHandler
End Control
Control BevelButton4 Inherits BevelButton
ControlInstance BevelButton4 Inherits BevelButton
EventHandler Sub Action()
player.stop
End EventHandler
End Control
Control Slider1 Inherits Slider
ControlInstance Slider1 Inherits Slider
EventHandler Sub ValueChanged()
player.volume = me.Value / 100.0
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control bar Inherits ProgressBar
ControlInstance bar(0) Inherits ProgressBar
ControlInstance bar(1) Inherits ProgressBar
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if player = nil then Return
if player.duration > 0 then
pos.Value = player.currentTime / player.duration * 200.0
else
pos.Value = 0
end if
End EventHandler
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control pos Inherits ProgressBar
ControlInstance pos Inherits ProgressBar
End Control
Control Timer2 Inherits Timer
ControlInstance Timer2 Inherits Timer
EventHandler Sub Action()
if player = nil then Return
player.updateMeters
dim c as integer = player.numberOfChannels
if c > 2 then c = 2
for i as integer = 0 to c-1
dim d as double = player.peakPowerForChannel(i)
bar(i).Value = d+160
if bar(i).Visible = false then
bar(i).Visible = true
end if
next
for i as integer = c to 1
if bar(i).Visible then
bar(i).Visible = false
end if
next
End EventHandler
End Control
Control Slider2 Inherits Slider
ControlInstance Slider2 Inherits Slider
EventHandler Sub ValueChanged()
player.pan = me.Value / 100.0
End EventHandler
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Property player As AVAudioPlayerMBS
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
FileTypes1
Filetype audio/mp3
Filetype audio/m4a
Filetype audio/m4b
Filetype audio/mpeg
Filetype audio/mpeg3
Filetype audio/aac
Filetype audio/aiff
End FileTypes1
End Project
The items on this page are in the following plugins: MBS AVFoundation Plugin.