AVAudioRecorder - Proper MPEG4 AAC Recording Settings

前端 未结 3 802
悲&欢浪女
悲&欢浪女 2021-02-06 04:52

I\'ve got a live app with an estimated 15% of users reporting that the record feature is not working. This isn\'t happening on our test devices, but the reports show that the p

相关标签:
3条回答
  • 2021-02-06 05:35

    Apologies that this is slightly tangential but I've just had a very similar issue with a number of users not being able to record, which I thought was related to audio settings.

    However for me it turned out that they had denied permission to access the microphone. This meant that prepareToRecord was working (and truncating the file) and record was reporting that it was working, but actually it wasn't recording anything.

    And I used this when I want to record:

    AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
        if granted {
            // can record - create AVAudioRecorder here
    
        } else {
            // can't record - update UI (or react accordingly)
        }
    })
    

    Hope it saves someone some time if they run into a similar issue.

    0 讨论(0)
  • 2021-02-06 05:38

    Try this settings which i used to record MPEG 4 AAC format...Its working good..

    NSString *tempDir = NSTemporaryDirectory();
    NSString *soundFilePath = [tempDir stringByAppendingPathComponent:@"sound.m4a"];
    
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
                                      [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
                                      [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                      [NSNumber numberWithFloat:8000.0], AVSampleRateKey,
                                      nil];
    
    0 讨论(0)
  • 2021-02-06 05:44

    it could be many things not having to do with the recording settings.

    the real question you want answered seems to be: what would cause the recording not to occur?

    audioRecorder could be nil or audioRecorder prepareToPlay could be returning NO. the former seems more likely.

    the url passed to initWithURL could be malformed: - have you tested by playing with the verseGUID, bRecordReference values? maybe your devices never have a bad verseGUID, but the devices on which no recording happens have a nil/empty verseGUID. this could cause the filename to be simply ".caf".

    you seem to have your own class method [Utilities sharedInstance] . could this work for some reason on your devices but not on the failing devices? if so, you could be asking to record in a top level directory when you did not mean to.

    can you get the testers you have onto a "beta" list? sign up for something like TestFlight or Hockey Kit, get one or more of the users with a failure to record to also sign up, and then upload a beta of your app with diagnostics that put a dialog on screen with the resultant "error". that might be most obvious. i use testflightapp.com only because it was the first i tried, it was pretty easy for me to manage and pretty painless for my beta testers.

    0 讨论(0)
提交回复
热议问题