所以我正在尝试编写一个几乎只是播放媒体播放器的 IBAction 的函数。这在我正在编写的代码中是必要的,因为将使用多个视频,因此为了使我的代码更简洁,我想编写该函数,以便媒体播放器的代码进入一次而不是多次。当我尝试下面的代码时,它表明我在 IBAction 上有一个错误,指出“预期的表达式”。有任何想法吗?代码中还包含一个注释掉的 if 语句,该语句不起作用。基本上我希望这样当我单击全屏媒体播放器中提供的默认“完成”按钮时,窗口将关闭。现在所有完成按钮所做的就是停止视频,但我希望媒体播放器也关闭。
void moviePlayer (id vidName, id type);
void moviePlayer (id vidName, id type){
-(IBAction)playMovie{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"vidName" ofType:@"type"]];
MPMoviePlayerController *playerViewController = [[MPMoviePlayerController alloc] init];
playerViewController.contentURL = url;
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
playerViewController.view.frame = CGRectMake(0, 0, 1030, 768);
}
else{
playerViewController.view.frame = CGRectMake(0,0, 768, 1004);
}
[playerViewController setControlStyle: MPMovieControlStyleFullscreen];
[playerViewController setScalingMode:MPMovieScalingModeAspectFit];
playerViewController.view.AutoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:playerViewController.view];
[playerViewController play];
/*if (playerViewController == stop){
[self.playerViewController.view removeFromSuperview];
}*/
self.playerViewController = playerViewController;
}
}