2012-02-19 103 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文件中。

相關問題