2013-04-08 118 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