When I try to play the data sample.mp3, I get the error "Insufficient Arguments".If you know, please let me know.
override func viewDidLoad(){
super.viewDidLoad()
let sound_data = NSURL (fileURLWithPath: NSBundle.mainBundle().pathForResource("sample", ofType:"mp3")!)
varaudioPlayer:AVAudioPlayer=AVAudioPlayer(contentsOfURL:sound_data, error:nil) // This is where the error occurs.
audioPlayer.play()
}
Swift2 introduced new syntaxes such as try
, catch
, throw
, which greatly changed the way error handling works.
At the same time, the NSError
argument disappears because the method of taking the NSError
double pointer is now automatically converted to throws
.Instead, you must invoke the method with try
.
let sound_data=NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("sample", ofType:"mp3")!)
do{
let audioPlayer=try AVAudioPlayer(contentsOfURL:sound_data)
audioPlayer.play()
} catchlet error as NSError {
print(error)
}
600 GDB gets version error when attempting to debug with the Presense SDK (IDE)
568 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 Understanding How to Configure Google API Key
610 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.