repeatmode doesn't work in MPMoviePlayerViewCo

2019-03-03 20:39发布

How to display a recorded video as repeat as an'n' number of times like in Vine Application.

Here I use the MPMoviePlayerViewController, and works great display the recorded video. But the problem is, it doesn't repeating.

Here the currently using code is,

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]];

And the NSNotification code,

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

Can anyone please give the solution..

Note: I'm using the XCode 4.5.2 tool and ios simulater 6.0

3条回答
姐就是有狂的资本
2楼-- · 2019-03-03 20:47

You have to keep the MPMoviePlayerController object as a member, otherwise the app would lose context to it and the movie will not loop.

查看更多
老娘就宠你
3楼-- · 2019-03-03 21:09

you can try this code

-(void) movieFinishedCallback:(NSNotification *) aNotification
{
    if (aNotification.object == self.moviePlayer) {
        NSInteger reason = [[aNotification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [playerController play];
        }
    }
}
查看更多
疯言疯语
4楼-- · 2019-03-03 21:11

Try this code. It is working.

    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];
查看更多
登录 后发表回答