2013-04-08 119 views
1

我正在使用MPMoviePlayerController,但我得到的问题是,它的重复只有两次,但我不得不重复它不断如何做,请任何人建议我更好的方式。如何在iphone中播放视频?

-(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]; 
     } 
    } 
} 
+0

粘贴outPutUrl – 2013-04-08 12:39:31

+0

我有过去outPutUrl路径已经跑了两次,但没有运行第三次。 – IOSDev 2013-04-08 12:41:22

+0

一旦粘贴outPutUrl在这里.. – 2013-04-08 12:43:49

回答

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

这是为我工作,不断打.....

+0

但我试过这个,它也是不工作,我该怎么做,请帮助我。 – IOSDev 2013-04-08 13:57:07

+0

它是为我工作伙计..好吧你已经复制这一个,并粘贴,也没有得到... – 2013-04-08 13:58:50

+0

是的,我真的试过这个,但它只运行一次 – IOSDev 2013-04-08 14:01:56