Home AVFoundation - cant find getDirectory
Reply: 0

AVFoundation - cant find getDirectory

akvag
1#
akvag Published in 2018-02-12 12:14:44Z

Hey guys i just started programming, and i want to make a recorder App, so i followed a tutorial on youtube, but its programmed in Swift 3 i believe, while i have Swift 4.

i get "Use of unresolved identifier 'getDirectory┬┤" , and "Value of type 'AVAudioRecorderDelegate' has no member 'delegate'" and "Value of type 'AVAudioRecorderDelegate' has no member 'record'" .

How can i fix this when i have already added func getDirectory() -> URL?

import AVFoundation


class RecordViewController: UIViewController, AVAudioRecorderDelegate {
    
    var recordingSession:AVAudioSession!
    var audioRecorder:AVAudioRecorderDelegate!
    
    var numberOfRecords = 0
    
    
    @IBOutlet weak var buttonLabel: UIButton!
    @IBAction func record(_ sender: Any)
        
    {
        //check
        if audioRecorder == nil
        {
            numberOfRecords += 1
            let filename = getDirectory().appendingPathComponent("\(numberOfRecords).m4a")
            
            
            let settings = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 12000, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue]
            
            // Start audio recording
            
            do
            {
                audioRecorder = try AVAudioRecorder(url: filename, settings: settings)
                audioRecorder.delegate = self
                audioRecorder.record()
            }
            catch
            {
        }
    
func getDirectory() -> URL
{
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let documentDirectory = paths[0]
    return documentDirectory
}

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.39495 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO