电影播放器​​在iOS SDK中没有完成通知

时间:2013-07-19 13:23:13

标签: iphone ios objective-c mpmovieplayercontroller

我播放了电影,但无法在电影结束时调用该方法。

我的代码如下:

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];

1 个答案:

答案 0 :(得分:0)

将此代码用于Media Player。

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");
}