我尝试在按下按钮时添加音频,但收到以下错误
"argument labels contentsOfURL, error doesn't match any overloaded Audio"
var ButtonAudioURL = NSURL(fileURLWithPath: Bundle.main.path(forResource: "Slag", ofType: "m4a")!)
var clickAudioPlayer = AVAudioPlayer()
class UIViewController: UIViewController {
clickAudioPlayer = AVAudioPlayer(contensOfURL: ButtonAudioURL, error: nil) //This is in this line i get the error
}
@IBAction func ASButton(_ sender: UIButton) {
}
错误发生在
clickAudioPlayer = AVAudioPlayer(contensOfURL: ButtonAudioURL, error: nil)
最佳答案
Swift 3.0,编译成功,这是我的代码:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer: AVAudioPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let audioURL = URL(fileURLWithPath: Bundle.main.path(forResource: "test", ofType: "mp3")!)
audioPlayer = try? AVAudioPlayer(contentsOf: audioURL)
print("test: \(audioURL), \(audioPlayer)")
}
}
关于 swift 3 : 'Doesn' t match any overloaded Audio' error when using AVAudioPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39669895/