0

如何像在 Vine 应用程序中一样将录制的视频显示为重复 n 次。

在这里,我使用 MPMoviePlayerViewController,可以很好地显示录制的视频。但问题是,它不会重复。

这里当前使用的代码是,

NSURL *url = [NSURL fileURLWithPath:videoPath];
playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];

playerController.view.frame = CGRectMake(200, 402, 300, 200);
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview: playerController.view];
[playerController.moviePlayer play];

NSLog(@"repeatMode: %d",playerController.moviePlayer.repeatMode);
[playerController.view addSubview:customview];


[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:[playerController moviePlayer]];

和 NSNotification 代码,

 - (void) movieFinishedCallback:(NSNotification*) aNotification
{
    NSLog( @"myMovieFinishedCallback: %@", aNotification );
    MPMoviePlayerController *movieController = aNotification.object;
    NSLog( @"player.playbackState = %d", movieController.playbackState );
}

任何人都可以请给出解决方案..

注意:我使用的是 XCode 4.5.2 工具和 ios 模拟器 6.0

4

3 回答 3

1

试试这个代码。这是工作。

    NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video" ofType:@"mp4"]];
    MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
    [moviePlayerController.moviePlayer prepareToPlay];
    [moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
    [moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
    [self.view addSubview:moviePlayerController.view];
于 2013-09-10T06:49:23.997 回答
0

你可以试试这段代码

-(void) movieFinishedCallback:(NSNotification *) aNotification
{
    if (aNotification.object == self.moviePlayer) {
        NSInteger reason = [[aNotification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [playerController play];
        }
    }
}
于 2013-09-10T04:37:33.243 回答
0

您必须将 MPMoviePlayerController 对象保留为成员,否则应用程序将失去它的上下文并且电影不会循环播放。

于 2014-12-28T17:24:11.547 回答