Getting SIGABRT signal when I try to play a video (Objective-C)

♀尐吖头ヾ 提交于 2019-12-12 02:30:04

问题


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]];

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

回答1:


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.

Peter



来源:https://stackoverflow.com/questions/9855310/getting-sigabrt-signal-when-i-try-to-play-a-video-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!