1

I do have error Thread1: EXC_BAD_INSTRUCTION. Been trying very hard on this. Any helpful personnel out there?

import UIKit import AVFoundation

class PlaySoundsViewController: UIViewController {

var filePathUrl: NSURL!
var audioPlayer: AVAudioPlayer?
var receivedAudio:RecordedAudio!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.


    audioPlayer = try! AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func playFastAudio(sender: UIButton) {
    audioPlayer!.stop()
    audioPlayer!.rate = 1.5
    audioPlayer!.currentTime = 0.0
    audioPlayer!.play()
}

@IBAction func playSlowAudio(sender: UIButton) {
    // play audio slow
    audioPlayer!.stop()
    audioPlayer!.rate = 0.5
    audioPlayer!.currentTime = 0.0
    audioPlayer!.play()


}
@IBAction func StopButtonSound(sender: UIButton) {
    audioPlayer!.stop()
}

}

CherChuan
  • 33
  • 5
  • I can't see that receivedAudio and relatively receivedAudio.filePathUrl is defined somewhere but you are using it in viewDidLoad to create AV object. – smozgur Feb 07 '16 at 21:19
  • Ah, likely passing via segue. What is the error line then? – smozgur Feb 07 '16 at 21:20
  • I am sorry for the misleading question. However, audioPlayer = try! AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl) fails me at runtime. – CherChuan Feb 09 '16 at 07:44
  • Are you passing the receivedAudio via segue from the parent view controller? Are you sure it is being passed actually? – smozgur Feb 09 '16 at 11:12

0 Answers0