MPAVController>>没有足够的缓冲来跟上

时间:2012-11-06 07:03:58

标签: iphone ios xcode ios6 audio-recording

我正在使用此代码播放视频。

player= [[ MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
player.navigationController.navigationBar.hidden = YES;
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
player.moviePlayer.fullscreen = NO;
[self presentModalViewController:player animated:NO];

视频播放工作完美但问题是,在完成播放后,我会在控制台中获得此结果。

[MPAVController] Autoplay: Likely to keep up or full buffer: 0
[MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.

然后我试图录制声音但无法录制。

任何人都可以帮我解决这个问题。

5 个答案:

答案 0 :(得分:1)

同样的任务由我完成......你可以参考我的代码......我希望它有所帮助......

- (IBAction) startRecording:(id)sender
{

    NSLog(@"**************Recording start**************");    

    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

    // We can use kAudioFormatAppleIMA4 (4:1 compression) or kAudioFormatLinearPCM for nocompression
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];

    // We can use 44100, 32000, 24000, 16000 or 12000 depending on sound quality
    [recordSetting setValue:[NSNumber numberWithFloat:41000.0] forKey:AVSampleRateKey];

    [recordSetting setValue:[NSNumber numberWithInt: kAudioFormatAppleLossless] forKey:AVFormatIDKey];

    // We can use 2(if using additional h/w) or 1 (iPhone only has one microphone)
    [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];

    [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];

    NSError *error;

    if (![[NSFileManager defaultManager] fileExistsAtPath:mediaPath])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:mediaPath withIntermediateDirectories:NO attributes:nil error:&error];
    }


    mediaPath = [[NSString stringWithFormat:@"%@/sound.caf", DOCUMENTS_FOLDER] retain];
    NSURL *url = [NSURL fileURLWithPath:mediaPath];
    NSLog(@"AUDIOPATH%@",mediaPath);
    err = nil;
    NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];

    if(audioData) {

        NSFileManager *fm = [NSFileManager defaultManager];
        [fm removeItemAtPath:[url path] error:&err];

    }

    err = nil;
    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];

    if(!audioRecorder){

        NSLog(@"audioRecorder : %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        UIAlertView *alert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: [err localizedDescription]
                                  delegate: nil cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [alert show];
        return;
    }

    //prepare to record
    [audioRecorder setDelegate:self];
    [audioRecorder prepareToRecord];

    audioRecorder.meteringEnabled = YES;

    BOOL audioHWAvailable = audioSession.inputIsAvailable;

    if (! audioHWAvailable) {

        UIAlertView *cantRecordAlert = [[UIAlertView alloc] initWithTitle: @"Warning"
                                                                  message: @"Audio input hardware not available"
                                                                 delegate: nil cancelButtonTitle:@"OK"
                                                        otherButtonTitles:nil];
        [cantRecordAlert show];
        [cantRecordAlert release];
        return;
    }

    // start recording
    [audioRecorder record];
}

答案 1 :(得分:0)

我不确定这是否会有所帮助,但您应该将MPMoviePlayerViewControllerpresentMoviePlayerViewControllerAnimated:一起展示,而不是presentModalViewController:animated:,如下所示:

[self presentMoviePlayerViewControllerAnimated:player];

如果您手动取消MPMoviePlayerViewController,则应使用dismissMoviePlayerViewControllerAnimated

Here is a thread 可能帮助解决MPAVController日志的问题。您似乎正在对MPMoviePlayerViewController moviePlayer进行大量自定义 - 您可以诚实地考虑使用MPMoviePlayerController代替MPMoviePlayerViewController

如果没有看到您用于执行录音的代码,则无法判断您的录音问题是否源于与MPMoviePlayerViewController有关或者您在其他地方有错误。我建议发布更多代码。

答案 2 :(得分:0)

您需要在播放视频后录制音频,因此您必须使用此通知才能知道电影播放器​​已完成播放视频...为此,您需要使用此代码。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:)
        name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];

在该moviePlaybackComplete:方法中,您可以录制音频。 为此,您最好使用AVAudioPlayer类。  现在使用这段代码进行录制..

AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];

答案 3 :(得分:0)

我还发现这些消息可能是由于向媒体播放器发送了错误的URL。有时真的很简单。

答案 4 :(得分:-1)

检查MPMoviePlayerController上的useApplicationAudioSession属性。在iOS 3.1.x中,电影播放器​​总是获得自己的系统提供的音频会话。在较新版本的iOS中,它现在可以共享应用程序会话,这也是默认值。尝试在开始播放电影之前将该属性切换为NO。