2012-07-30 17 views
0

所以我想写一个功能,几乎只是一个播放媒体播放器的IBAction。在编写的代码中,这是非常必要的,因为将会使用多个视频,以便使我的代码更加简洁,我希望编写该函数,以便媒体播放器的代码只进入一次,而不是几次。当我尝试下面的代码时,它声明我在IBAction上有一个错误,指出“预期表达式”。有任何想法吗?代码中还包含注释掉的语句,如果不起作用。本质上,我希望这样,当我点击全屏媒体播放器中提供的默认“完成”按钮时,该窗口将关闭。现在,所有完成按钮都会停止播放视频,但我希望媒体播放器也可以关闭。功能内的预期表达式错误

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

看的这部分代码:

void moviePlayer (id vidName, id type){ 


-(IBAction)playMovie{ 

就启动了一个C函数和不要将其关闭,然后尝试启动Objective C的方法。可能这会更好?

void moviePlayer (id vidName, id type){ 
} 
-(IBAction)playMovie{ 
    // other code 
} 
+0

不会那个括号刚刚关闭该函数,以便IBAction不会包含在该函数中。我觉得这会导致函数无用,因为函数体 – Pkolms 2012-07-31 23:12:02

+0

中没有任何内容正确。你不能在函数中使用函数,或者在方法中使用函数,或者在两者的yyy组合中使用类似的xxx。 – demosten 2012-08-02 19:21:26