swift 3 : 'Doesn' t match any overloaded Audio' error when using AVAudioPlayer

标签 swift xcode swift3 xcode8

我尝试在按下按钮时添加音频,但收到以下错误

"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/

相关文章:

arrays - 数组包含一个完整的子数组

ios - UISearchBar 在单击时修改其框架/边界

cocoa - 如何在 cocoa 中检测电源键何时被按下?

xcode - NSDateFormater +0000

ios - 如何设置本地通知在首次设置通知后每秒触发一次?

ios - 如何在没有完成处理程序的情况下快速从非泛型方法调用泛型方法

ios - 如何设置 UIImageView 大小以及如何确保它始终保持该大小?

swift - 为什么我的 PageViewController 的数据源不能正常工作?

ios - AppDelegate.swift 中没有这样的模块 'AWSMobileClient' 错误

ios - 如何实现method swizzling swift 3.0?