1

我正在使用 MPMoviePlayerController 但我遇到的问题是它只重复两次但我必须不断重复它如何做到这一点请任何人建议我更好的方法。

-(void)viewDidLoad
{
    player = [[MPMoviePlayerController alloc] initWithContentURL:outPutUrl];

    player.view.frame = CGRectMake(0, 0, 320, 480);
    player.repeatMode = MPMovieRepeatModeOne;

    [player setShouldAutoplay:YES];
    [player prepareToPlay];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:player];
    [player setControlStyle:MPMovieControlStyleNone];

    [self.imgView addSubview:player.view];

    [player play];
}
-(void)moviePlayerDidFinish:(NSNotification *)note
{
    if (note.object == player)
    {
        NSLog(@"this is note%@",note.object);

        NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];

        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [player play];
        }
    }
}
4

1 回答 1

1
- (void)viewDidLoad
{
    [super viewDidLoad];
    player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"drvo_hd_final-1" ofType:@"mp4"]]];
    player.view.frame = CGRectMake(20, 20, 280, 200);
    player.repeatMode = MPMovieRepeatModeOne;
    [player setShouldAutoplay:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidFinish:)  name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [player setControlStyle:MPMovieControlModeDefault];
    [self.view addSubview:player.view];
    [player prepareToPlay];
}

- (void)moviePlayerDidFinish:(NSNotification *)note
{
    if (note.object == player)
    {
        NSLog(@"this is note%@",note.object);
        NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [player prepareToPlay];
        }
    }
}

这对我有用并不断播放......

于 2013-04-08T13:23:50.523 回答