所以我试图编写一个几乎只是一个播放媒体播放器的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;
}
}
答案 0 :(得分:0)
看看代码的这一部分:
void moviePlayer (id vidName, id type){
-(IBAction)playMovie{
启动C函数并不关闭它然后尝试启动Objective C方法。可能这会更好吗?
void moviePlayer (id vidName, id type){
}
-(IBAction)playMovie{
// other code
}