【问题标题】:Getting SIGABRT signal when I try to play a video (Objective-C)当我尝试播放视频时获得 SIGABRT 信号(Objective-C)
【发布时间】:2012-03-24 20:28:46
【问题描述】:

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

两个问题:我的代码有什么问题? 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

【问题讨论】:

  • 你知道如何查看崩溃报告吗?检查那里可能会给你一些线索。这可能是由未捕获的异常引起的
  • @tams 我对 iPhone 开发非常陌生,这是我在 Objective-c 中的第一个项目。我不知道如何查看崩溃报告。我怎样才能做到这一点?这只是输出日志中的内容吗?在日志中它说:在抛出“NSException”实例后调用终止
  • 好的,我想如果你是新手,你可以从调试你的视图做加载方法开始。在方法的开头放置一个断点并单步执行代码。确保所有变量都正确,并且字符串设置正确。也许问题出在那儿。

标签: iphone objective-c memory mpmovieplayercontroller sigabrt


【解决方案1】:

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

彼得

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2021-06-17
    • 2013-03-07
    • 1970-01-01
    相关资源
    最近更新 更多