2012-03-24 48 views
0

当我尝试加载视频时,我收到一个引发的SIGABRT。以下是我的代码。如果有人能让我知道为什么我会得到这个错误,那会很好。正在为该行引发信号:theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];当我尝试播放视频时获取SIGABRT信号(Objective-C)

两个问题:我的代码有什么问题? SIGABRT通常意味着什么?

#import "Video.h" 
#import "MyManager.h" 

#进口

@implementation Video 

MPMoviePlayerController* theMovie; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 

    } 
    return self; 
} 

- (void)dealloc{ 
    [theMovie release]; 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    MyManager *sharedManager = [MyManager sharedManager]; 
    NSString *tempName = sharedManager.vidName; 
    NSString *url = [[NSBundle mainBundle] pathForResource:sharedManager.vidName ofType:@"mp4"]; 
    theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; 
    theMovie.scalingMode = MPMovieScalingModeAspectFit; 
    [theMovie.view setFrame:self.view.bounds]; 
    [self.view addSubview:theMovie.view]; 
    [theMovie play]; 

    } 

-(void)movieFinishedCallBack:(NSNotification *) aNotification{ 
    theMovie = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; 
    [theMovie.view removeFromSuperview]; 
    [theMovie pause]; 
    [theMovie stop]; 
} 

-(void) viewWillDisappear:(BOOL)animated{ 
    [theMovie pause]; // assume myMoviePlayer is an instance variable 
    [theMovie stop]; 
    theMovie = nil; 
    [theMovie release]; 
} 

- (void)viewDidUnload 
{ 
    [theMovie pause]; // assume myMoviePlayer is an instance variable 
    [theMovie stop]; 
    theMovie = nil; 
    [theMovie release]; 

    [super viewDidUnload]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 
+0

你知道如何查看崩溃报告吗?检查可能会给你一些线索。这可能是由于一个未捕获的异常 – tams 2012-03-24 20:48:59

+0

@tams我对iPhone开发非常陌生,这是我在Objective-c中的第一个项目。我不知道如何查看崩溃报告。我该如何解决这个问题?这正是输出日志中的内容吗?在日志中说:抛出'NSException' – 2012-03-24 20:52:12

+0

的实例后调用terminate,我认为如果你是新的,你可以开始调试你的视图的确实加载方法。在方法的开始处放置一个断点并逐步执行代码。确保你所有的变量都是正确的,并且你的字符串设置正确。问题可能在那里。 – tams 2012-03-24 20:57:51

回答

0

我发现,当您尝试访问的对象不存在或为空引用是SIGABRT错误通常出现。 所以也许你的问题是该文件不存在或者你可能丢失了对你的文件或你的videoplayer对象的引用。

彼得

相关问题