【问题标题】:ios - Recording Audio After VIdeo playios - 播放视频后录制音频
【发布时间】:2023-04-03 11:03:01
【问题描述】:

播放视频后我无法录制音频,如果我在播放视频之前录制没问题,但我必须关闭应用程序才能再次录制。 播放视频后无法录制音频,如果我在播放视频之前录制没问题,但我必须关闭应用程序才能重新录制。

录制音频:

- (IBAction)recordAudio:(id)sender {

dirPaths = NSSearchPathForDirectoriesInDomains(
                                               NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

NSString *soundFilePath = [docsDir
                           stringByAppendingPathComponent:@"sound.caf"];

NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

NSDictionary *recordSettings = [NSDictionary
                                dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithInt:AVAudioQualityMin],
                                AVEncoderAudioQualityKey,
                                [NSNumber numberWithInt:16],
                                AVEncoderBitRateKey,
                                [NSNumber numberWithInt: 2],
                                AVNumberOfChannelsKey,
                                [NSNumber numberWithFloat:44100.0],
                                AVSampleRateKey,
                                nil];

NSError *error = nil;

_audioRecorder = [[AVAudioRecorder alloc]
                  initWithURL:soundFileURL
                  settings:recordSettings
                  error:&error];

if (error)
{
    NSLog(@"error: %@", [error localizedDescription]);
} else {
    [_audioRecorder prepareToRecord];
}

if (!_audioRecorder.recording)
{
    _playButton.enabled = NO;
    _stopButton.enabled = YES;
    [_audioRecorder record];

}
}

【问题讨论】:

    标签: ios audio mpmovieplayercontroller record avaudiorecorder


    【解决方案1】:

    在录制音频之前执行此操作:

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
    

    【讨论】:

    • 工作!非常感谢:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多