0

我必须背靠背播放两个音频文件。我有一个通用文件,上面写着:“我的名字是”

然后跟随另一个具有另一个音频字符串的音频文件。

例如:说 a.mp3 有“我的名字是” b.mp3 有“约翰”

但是当我设置 MPMoviePlayerController 的 contentURL 时。它跳过第一个音频并播放第二个音频。

这是我的代码:

- (void) playPromptAudio
{[appDelegate.globalPlayer setContentURL:[NSURL 
             URLWithString:@"http://localhost/a.mp3"]];

    [appDelegate.globalPlayer prepareToPlay];
    [appDelegate.globalPlayer play];

    while (appDelegate.globalPlayer.playbackState == MPMoviePlaybackStatePlaying ) {
        // dirty hack, do gracefully
        // do nothing
    }

    [appDelegate.globalPlayer setContentURL:[NSURL URLWithString:@"http://localhost/b.mp3"]];
        [appDelegate.globalPlayer prepareToPlay];
    [appDelegate.globalPlayer play];
}

但是当我运行代码时,只播放“John”。

调试代码后,我看到音频在执行整个函数后开始播放,所以很明显“John”是最后设置的。但是有没有办法防止这种行为?

4

1 回答 1

0

试试这个链接 MPMoviePlayerController 播放

下面的代码 Play MpMoviePlayer with nodification:

        NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO];
        self.moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url]
                    autorelease];
        moviePlayer.shouldAutoplay = NO;
        moviePlayer.view.frame = view_video.bounds;
        moviePlayer.scalingMode= MPMovieScalingModeFill;
        moviePlayer.controlStyle =MPMovieControlStyleNone;
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(doneButtonClick:) 
                                                     name:MPMoviePlayerPlaybackDidFinishNotification 
                                                   object:nil];
        [moviePlayer Play]; 

下面的函数称为 MpMovieplayerController Playbackfinished:

     -(void)doneButtonClick:(NSNotification*)aNotification{
        NSLog(@"MPMoviePlayer is finished..!");
     }

谢谢....!

于 2012-04-26T12:49:04.337 回答