0

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

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.

然后在我尝试录制声音但无法录制之后。

谁能帮我解决这个问题。

4

5 回答 5

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];
}
于 2013-01-03T11:11:21.457 回答
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];
于 2012-11-15T09:18:09.157 回答
0

我不确定这是否会有所帮助,但您应该向您展示MPMoviePlayerViewControllerpresentMoviePlayerViewControllerAnimated :,而不是presentModalViewController:animated:像这样:

[self presentMoviePlayerViewControllerAnimated:player];

如果您手动关闭MPMoviePlayerViewController您应该使用dismissMoviePlayerViewControllerAnimated.

这是一个可能有助于解决 MPAVController 日志问题的线程。似乎您MPMoviePlayerViewController moviePlayer正在MPMoviePlayerControllerMPMoviePlayerViewController.

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

于 2012-11-12T15:28:07.110 回答
0

我还发现这些消息可能是由于向媒体播放器发送了不正确的 URL 引起的。有时候真的就是这么简单。

于 2012-12-11T10:48:40.607 回答
-1

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

于 2012-11-12T18:27:38.310 回答