#AudioKit 播放音序器音频 mp3
Posted
技术标签:
【中文标题】#AudioKit 播放音序器音频 mp3【英文标题】:#AudioKit Play sequencer audios mp3 【发布时间】:2018-06-12 14:56:56 【问题描述】:我正在尝试使用 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)"
【问题讨论】:
【参考方案1】:AKSequencer 用于播放 MIDI 文件。要播放 mp3 文件,您可以使用 AKPlayer http://audiokit.io/docs/Classes/AKPlayer.html
【讨论】:
以上是关于#AudioKit 播放音序器音频 mp3的主要内容,如果未能解决你的问题,请参考以下文章
是否可以在播放 AudioKit 音序器时修改 MusicSequnce
Audiokit:(V5)音序器无法在轨道的同一位置同时播放音符
Swift - 带有振荡器的 AudioKit 音序器(AKOscillatorBank).频率不会在更高的范围内播放(MidiNote 120+)