2013-07-19 38 views
2

我播放了電影,但無法在電影完成時調用該方法。電影播放器​​沒有完成通知在iOS SDK中沒有觸發

我的代碼如下:

MPMoviePlayerViewController *pv=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:@"Video_path"]]]; 

MPMoviePlayerController *pc=[pv moviePlayer]; 

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

[self presentViewController:pv animated:YES completion:nil]; 

[pc prepareToPlay]; 

[pc play]; 

回答

0

使用此代碼的媒體播放器。

MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:URL or Path of file]; 
    theMovie.scalingMode=MPMovieScalingModeAspectFill; 

    theMovie.view.frame = CGRectMake(60, 20, 700, 500); 
    theMovie.view.center = self.view.center; 

    [self.view addSubview:theMovie.view]; 

    // Register for the playback finished notification. 

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



-(void)onStop 
{ 
    NSLog(@"Movie Stopped"); 
} 
+0

感謝您的回覆...... !!但它只顯示黑屏和視頻未播放 – user2526811

+0

[theMovie play]需要用來播放它。 –

+0

是的,已經試過這個,但得到了同樣的結果。如果我使用'MoviePlayerViewController',那麼它運行良好,但委託方法不會被調用。 – user2526811