2017-02-08 16 views
0

は私が私の見解の背景としてビデオを再生したいと私はそのような何か作っ:無限のビデオ再生IOS

NSString *pathForFile = [[NSBundle mainBundle] pathForResource:@"clear" ofType:@"mp4"]; 
player = [[MPMoviePlayerController alloc] init]; 
player.shouldAutoplay = YES; 
player.repeatMode = MPMovieRepeatModeNone; 
player.fullscreen = YES; 
player.movieSourceType = MPMovieSourceTypeFile; 
player.scalingMode = MPMovieScalingModeAspectFill; 
player.contentURL =[NSURL fileURLWithPath:pathForFile]; 
player.controlStyle = MPMovieControlStyleNone; 
[player.view setFrame:self.view.bounds]; 
[player.view setUserInteractionEnabled:NO]; 
[player.view setAlpha:0.0f]; 
[self.view addSubview:player.view]; 
[self.view sendSubviewToBack:player.view]; 
[player prepareToPlay]; 

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

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

私のメソッドが呼び出されるたびに、ビデオが終了プレーヤーは再びビデオを再生しません。私は間違って何をしていますか?

ありがとうございます。

+0

[player seekToTime:kCMTimeZero];この行をif(reason == MPMovieFinishReasonPlaybackEnded){}の条件で使用すると、いくつかのループの後に –

答えて

0
- (void)moviePlayerDidFinish:(NSNotification *)note { 
    if (note.object == player) { 
     NSInteger reason = [[note.userInfo objectForKey:@"MPMoviePlayerPlaybackDidFinishReasonUserInfoKey"] integerValue]; 
     if (reason == MPMovieFinishReasonPlaybackEnded) { 
      player.seekToTime[kCMTimeZero]; 
      // you must have to give time to start video again so use seekToTime 
      [player play]; 
     } 
    } 
} 
+0

の再生が停止する@himanshu –

+0

再生回数? @AlexChekel –

+1

@AlexChekelあなたのソリューションの別のオプションは、AVPlayerLooper –

関連する問題