#AudioKit 播放音序器音频 mp3
#AudioKit Play sequencer audios mp3
我正在尝试使用 AudioKit 库播放音频 mp3 列表。我阅读了有关音序器的信息,并在官方 AudioKit Doc 的示例中看到了所有代码。
调用方法 sequencer.play() 后没有声音。
var audios:[String] = [
"/Users/rubenpalma/Documents/mp3/hola.mp3",
"/Users/rubenpalma/Documents/mp3/prueba.mp3",
"/Users/rubenpalma/Documents/mp3/mundo.mp3",
"/Users/rubenpalma/Documents/mp3/test.mp3",
"/Users/rubenpalma/Documents/mp3/hi.mp3",
"/Users/rubenpalma/Documents/mp3/adios.mp3"
]
var path = playAudios(background: back, audiosPath: audios)
func playAudios(background:String,audiosPath:[String]) -> String {
var durationBackground = 0.00
let midi = AKMIDI()
let sequencer = AKSequencer()
let mixer = AKMixer()
do{
var i = 0
for path in audiosPath {
let fileAudioURL = NSURL(fileURLWithPath: path)
if let audio = try? AKAudioFile(forReading: fileAudioURL as URL) {
print("\(path) size:\(audio.duration)")
let sampler = AKMIDISampler()
try sampler.loadAudioFile(audio)
sampler.enableMIDI(midi.client, name: "Sampler_\(i)")
mixer.connect(input: sampler)
let track = sequencer.newTrack("t_\(i)")
track?.setMIDIOutput(sampler.midiIn)
track?.add(noteNumber: MIDINoteNumber(i), velocity: 127, position: AKDuration(beats:Double(0)), duration: AKDuration(beats:audio.duration*2), channel:1)
print("is empty? \(track!.isEmpty)")
durationBackground += audio.duration
i += 1
}
}
AudioKit.output = mixer
try AudioKit.start()
sequencer.play()
print("playing.. \(sequencer.isPlaying) ")
}catch{
print("Unexpected non-vending-machine-related error: \(error)")
}
return "duration \(durationBackground)"
}
AKSequencer是播放midi文件。要播放 mp3 文件,您需要使用 AKPlayer http://audiokit.io/docs/Classes/AKPlayer.html
我正在尝试使用 AudioKit 库播放音频 mp3 列表。我阅读了有关音序器的信息,并在官方 AudioKit Doc 的示例中看到了所有代码。 调用方法 sequencer.play() 后没有声音。
var audios:[String] = [
"/Users/rubenpalma/Documents/mp3/hola.mp3",
"/Users/rubenpalma/Documents/mp3/prueba.mp3",
"/Users/rubenpalma/Documents/mp3/mundo.mp3",
"/Users/rubenpalma/Documents/mp3/test.mp3",
"/Users/rubenpalma/Documents/mp3/hi.mp3",
"/Users/rubenpalma/Documents/mp3/adios.mp3"
]
var path = playAudios(background: back, audiosPath: audios)
func playAudios(background:String,audiosPath:[String]) -> String {
var durationBackground = 0.00
let midi = AKMIDI()
let sequencer = AKSequencer()
let mixer = AKMixer()
do{
var i = 0
for path in audiosPath {
let fileAudioURL = NSURL(fileURLWithPath: path)
if let audio = try? AKAudioFile(forReading: fileAudioURL as URL) {
print("\(path) size:\(audio.duration)")
let sampler = AKMIDISampler()
try sampler.loadAudioFile(audio)
sampler.enableMIDI(midi.client, name: "Sampler_\(i)")
mixer.connect(input: sampler)
let track = sequencer.newTrack("t_\(i)")
track?.setMIDIOutput(sampler.midiIn)
track?.add(noteNumber: MIDINoteNumber(i), velocity: 127, position: AKDuration(beats:Double(0)), duration: AKDuration(beats:audio.duration*2), channel:1)
print("is empty? \(track!.isEmpty)")
durationBackground += audio.duration
i += 1
}
}
AudioKit.output = mixer
try AudioKit.start()
sequencer.play()
print("playing.. \(sequencer.isPlaying) ")
}catch{
print("Unexpected non-vending-machine-related error: \(error)")
}
return "duration \(durationBackground)"
}
AKSequencer是播放midi文件。要播放 mp3 文件,您需要使用 AKPlayer http://audiokit.io/docs/Classes/AKPlayer.html