2013-07-04 48 views
0

我正在開發iOS應用程序,並且我想在用戶按下按鈕時播放視頻。 我已經開發了這個,用戶按下按鈕並播放視頻,但是當視頻結束時,視頻的視圖仍然存在,並且視頻的最後一幀被凍結。iOS-Xcode:在最後一幀中凍結的視頻複製

我已經搜索在谷歌,我發現這樣一個問題:

iOS 6, Xcode 4.5 video not exiting when done playing

我用代碼編寫的有,但我還沒有固定它。 這是我的代碼:

-(IBAction)reproducirVideo:(id)sender 
{ 
NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
             pathForResource:@"instrucciones"  ofType:@"mp4"]]; 
_moviePlayer = [[MPMoviePlayerController alloc] 
        initWithContentURL:url5]; 

_moviePlayer.controlStyle = MPMovieControlStyleDefault; 
_moviePlayer.shouldAutoplay = YES; 
[self.view addSubview:_moviePlayer.view]; 
[_moviePlayer setFullscreen:YES animated:YES]; 
} 

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{ 
[_moviePlayer.view removeFromSuperview]; 
_moviePlayer = nil; 
} 


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification { 
[_moviePlayer stop]; 
[_moviePlayer.view removeFromSuperview]; 
_moviePlayer = nil; 
} 

回答

1

很抱歉給您帶來不便,但我已經閱讀了這個問題,我只是固定它:

MPMoviePlayerController will not automatically dismiss movie after finish playing (ios 6)

這是正確的代碼:

- (IBAction)reproducirVideo:(id)sender 
{ 
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
            pathForResource:@"instrucciones" ofType:@"mp4"]]; 
_moviePlayer = 
[[MPMoviePlayerController alloc] 
initWithContentURL:url]; 

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:_moviePlayer]; 

_moviePlayer.controlStyle = MPMovieControlStyleDefault; 
_moviePlayer.shouldAutoplay = YES; 
[self.view addSubview:_moviePlayer.view]; 
[_moviePlayer setFullscreen:YES animated:YES]; 
} 

- (void) moviePlayBackDidFinish:(NSNotification*)notification { 

MPMoviePlayerController *player = [notification object]; 

[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:player]; 

if ([player 
    respondsToSelector:@selector(setFullscreen:animated:)]) 
{ 
    [player setFullscreen:NO animated:YES]; 
    [player.view removeFromSuperview]; 
} 
} 

謝謝!你拯救了我的生命

致以問候

相關問題