我尝试播放视频时获取SIGABRT信号(Objective-C)

时间:2012-03-24 20:28:47

标签: iphone objective-c memory mpmovieplayercontroller sigabrt

当我尝试加载视频时,我收到一个SIGABRT。以下是我的代码。如果有人能让我知道为什么我会收到这个错误,那就太好了。该行正在抛出信号:theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];

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

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

#import

@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

1 个答案:

答案 0 :(得分:0)

我发现当您尝试访问不存在的对象或者是空引用时,通常会出现Sigabrt错误。 所以也许你的问题是文件不存在,或者你丢失了对你的文件或你的视频播放器对象的引用。

彼得