2012-02-19 111 views
0

大家好我有一个问题,在iOS 5中播放视频。当我构建程序时,我得到一个警告“隐藏实例变量的本地声明”,当我运行该程序并点击按钮我得到一个“SIGABRT”。我不知道该怎么做,我能得到的所有帮助都是非常有趣的!iOS 5电影播放器​​

THX提前

MY .h文件中

 #import <MediaPlayer/MediaPlayer.h> 

    @interface MainViewController : UIViewController { 

    MPMoviePlayerController *moviePlayer; 


} 


-(IBAction)Video:(id)sender; 

@end 

MY .m文件

#import "MainViewController.h" 

@interface MainViewController() 

@end 


@implementation MainViewController 


-(IBAction)Video:(id)sender { 

MPMoviePlayerController *moviePlayer; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"]; 
NSURL *videoURL = [NSURL fileURLWithPath:path]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
[moviePlayer setControlStyle:MPMovieControlStyleDefault]; 
[moviePlayer.view setFrame: self.view.bounds]; 
[self.view addSubview: moviePlayer.view]; 
[moviePlayer prepareToPlay]; 
[moviePlayer play]; 
} 



- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 

回答

0
local declaration of hides instance variables 

删除您-(IBAction)Video:(id)sender方法的第一行。

MPMoviePlayerController *moviePlayer; //this line; 

因为您已经在.h文件中声明了这样的变量。

0

意味着你声明了两次相同的变量名,一个在.h文件中,另一个在.m文件中。