2010-07-15 105 views
1

我在面對一個ipad視頻合併問題。我的代碼工作正常我的意思是播放視頻,但一旦視頻到達結束。回調方法不被調用。iPad videoPlayerDidFinishPlaying回調方法沒有響應

按下播放視頻按鈕時調用此方法。

-(IBAction) playVideo : (id) sender 
{ 
    [self initPlayingVideo:@"toyVid.mp4"]; 
} 

該方法處理視頻播放。

-(void) initPlayingVideo: (NSString *) videoFile 
{ 
    NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:videoFile]; 

    theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]]; 
    theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    theMovie.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 


    [self.view addSubview:theMovie.view]; 

    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(videoPlayerDidFinishPlaying 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:theMovie]; 

    videoPlayer = [theMovie moviePlayer]; 
    [videoPlayer play]; 
} 

這是回調方法。

-(void) videoPlayerDidFinishPlaying: (NSNotification*)aNotification 
{ 
    theMovie = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie.moviePlayer]; 
    [videoPlayer stop]; 
    [theMovie.moviePlayer release]; 
    [videoPlayer release]; 
    [theMovie.view removeFromSuperview]; 
} 

我在哪裏做錯了?請指導。在您的選擇和):

問候 蘭詹

+0

您可能會考慮將代碼放在代碼段中:只需在代碼前放置四個空格即可。 – 2010-07-15 05:17:49

回答

0

你錯過?我猜)可能是你的錯字,否則你不能編譯你的代碼。您的選擇需要一個參數。它應該是:

selector:@selector(videoPlayerDidFinishPlaying:) 

這將匹配您的實例方法。我想你沒有一個沒有參數。

+0

感謝您的回覆David。 監聽器功能如下。冒號(:)和右括號「)」在那裏。 [[NSNotificationCenter defaultCenter] \t的addObserver:自 \t選擇器:@selector(videoPlayerDidFinishPlaying :) \t名:MPMoviePlayerPlaybackDidFinishNotification \t對象:theMovie]; – TechBee 2010-07-15 05:33:56

+0

對象錯了。 對象:[theMovie moviePlayer]; – TechBee 2010-07-15 07:04:41