【发布时间】:2020-03-27 13:06:24
【问题描述】:
我有以下播放文件的方法。
let filePath = "/Users/fractor/Desktop/TestFile.mp3"
var file : AVAudioFile?
var audioEngine = AVAudioEngine()
var playerNode = AVAudioPlayerNode()
@IBAction func play(_ sender: Any) {
do {
file = try AVAudioFile(forReading: URL(fileURLWithPath: filePath))
} catch let error {
print(error.localizedDescription)
return
}
audioEngine.attach(playerNode)
audioEngine.connect(playerNode, to: audioEngine.mainMixerNode, format: file!.processingFormat);
do {
try audioEngine.start()
} catch let error {
print(error.localizedDescription)
return
}
audioEngine.mainMixerNode.pan = 100 // No effect
playerNode.scheduleFile(file!, at: nil){}
DispatchQueue.global(qos: .background).async {
print("audioEngine.isRunning = \(self.audioEngine.isRunning)");
self.playerNode.play();
print("playerNode.isPlaying = \(self.playerNode.isPlaying)");
}
}
文件播放正常,但平移值无效。我尝试了不同的值(-1、1、-100、+100),对于所有这些,立体声播放都保持在中间。
我需要做什么才能使平移工作?
【问题讨论】:
-
是的 pan 被记录在 -1 和 1 之间。但是,this post 似乎表明文档和现实之间可能存在差异。正如我所说,我已经尝试了许多值,包括记录范围的极端值。
-
我没有注意到 AVAudioPlayerNode 上的平移,这确实有效,谢谢。
-
添加了缺少的声明。
-
帖子似乎是正确的。 -100 到 100 似乎是正确的范围。
-
不知道为什么 pan 不能在混音器上工作,但你解决了我的问题。平移现在有效。一定要把它作为答案。
标签: swift macos avfoundation avaudioengine