1

MPMoviePlayerController を使用していますが、2 回しか繰り返されないという問題が発生していますが、その方法を継続的に繰り返す必要があるため、より良い方法を提案してください。

-(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 に答える