我在ipad视频中遇到了问题。我的代码工作正常我的意思是它播放视频,但一旦视频到达终点。不调用回调方法。
按下播放视频按钮时会调用此方法。
-(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 :(得分:0)
你错过了选择中的:和)吗?我想)可能是你的拼写错误,否则你无法编译你的代码。您的选择需要一个参数。它应该是:
selector:@selector(videoPlayerDidFinishPlaying:)
这将与您的实例方法匹配。我猜你没有参数。