Similar Posts

One Comment

  1. I finished everything even the darth vader and chipmunk because I skipped this problem but audioRecorderDidFinishRecording isn’t being called so the segue is never performed! Here is my code:

    //
    // RecordSoundsViewController.swift
    // Pitch Perfect
    //
    // Created by Daniel Wang on 8/23/15.
    // Copyright (c) 2015 Daniel Wang. All rights reserved.
    //

    import UIKit
    import AVFoundation
    class RecordSoundsViewController: UIViewController ,AVAudioRecorderDelegate{
    var recordedAudio:RecordedAudio!
    var audioRecorder:AVAudioRecorder!
    @IBOutlet weak var recordButton: UIButton!

    @IBOutlet weak var recordLabel: UILabel!
    @IBOutlet weak var stopButton: UIButton!

    @IBOutlet weak var recordingInProgress: UIButton!

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }
    override func viewWillAppear(animated: Bool) {
    //hide the stop button
    stopButton.hidden=true
    recordButton.enabled=true
    recordLabel.hidden=true
    }

    @IBAction func recordAudio(sender: UIButton) {
    recordButton.enabled=false
    stopButton.hidden=false
    recordLabel.hidden=false
    let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String

    let recordingName = “my_pitch_perfect_audio.wav”
    let pathArray = [dirPath, recordingName]
    let filePath = NSURL.fileURLWithPathComponents(pathArray)
    println(filePath)

    var session = AVAudioSession.sharedInstance()
    session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)

    audioRecorder = AVAudioRecorder(URL: filePath, settings: nil, error: nil)
    audioRecorder.meteringEnabled = true
    audioRecorder.prepareToRecord()
    audioRecorder.record()
    }
    func audioRecorderDidFinishRecording(recorder: AVAudioRecorder, successfully flag: Bool) {
    recordedAudio=RecordedAudio()
    recordedAudio.filePathUrl=recorder.url
    recordedAudio.title=recorder.url.lastPathComponent
    self.performSegueWithIdentifier(“stopRecording”, sender: recordedAudio)

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier==”stopRecording”){
    let playSoundsVC:PlaySoundsViewController=segue.destinationViewController as! PlaySoundsViewController
    let data=sender as! RecordedAudio
    playSoundsVC.receivedAudio=data
    }
    }

    @IBAction func stopAudio(sender: UIButton) {

    recordingInProgress.hidden=true
    //Inside func stopAudio(sender: UIButton)
    audioRecorder.stop()
    var audioSession = AVAudioSession.sharedInstance()
    audioSession.setActive(false, error: nil)
    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *