问题
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