尝试播放视频时收到SIGABRT信号(Objective-C)

问题描述:

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

When I try to load a video, I'm getting a SIGABRT thrown. Below is my code. If anybody could let me know why I'm getting this error, that would be great. The signal is being thrown for the line: theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];

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

Two questions: what is wrong with my code? and what does SIGABRT usually mean?

#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

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

I find that Sigabrt errors usually appear when you try to access an object that is not there or is a null reference. So maybe your problem is that the file does not exist or maybe you have lost a reference to your file or your videoplayer object somewhere.

彼得