【问题标题】:I'm getting SIGABRT when I try to load a video (objective-c)我尝试加载视频时收到 SIGABRT(objective-c)
【发布时间】:2012-03-26 23:28:16
【问题描述】:

所以我遇到的问题是,当我尝试以这种方式加载视频时:

-(void) viewDidLoad
{
MyManager *sharedManager = [MyManager sharedManager];
[super viewDidLoad];
NSString *tempName = sharedManager.vidName;
NSLog(@"%@", tempName);

//This is where the problem is being caused
NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:@"mp4"];
//This is where I'm getting the SIGABRT thrown
MPMoviePlayerController* 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];

}

由于 NSException,我在代码中指定的位置抛出了 SIGARBT。但是,如果我简单地写出字符串,如下:

- (void)viewDidLoad
{
MyManager *sharedManager = [MyManager sharedManager];
[super viewDidLoad];
NSString *tempName = sharedManager.vidName;
NSLog(@"%@", tempName);

//This is the line I changed
NSString *url = [[NSBundle mainBundle] pathForResource:@"vid_name" ofType:@"mp4"];

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

}

代码运行良好。问题可能是什么?我 NSLog tempName 以确保它包含正确的字符串并且它是。此外,sharedManager.vidName 是一个 NSMutableString。这是唯一让我无法完成高级项目和大学毕业的问题,因此我们将不胜感激任何帮助。谢谢。

这是我在日志中得到的内容:

2012-03-26 22:04:52.115 SeniorProject[20502:207] Barbell Incline Bench Press - Medium Grip
2012-03-26 22:04:52.120 SeniorProject[20502:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** Call stack at first throw:
(
0   CoreFoundation                      0x00fb15a9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x01105313 objc_exception_throw + 44
2   CoreFoundation                      0x00f69ef8 +[NSException raise:format:arguments:] + 136
3   CoreFoundation                      0x00f69e6a +[NSException raise:format:] + 58
4   Foundation                          0x007e3ab6 -[NSURL(NSURL) initFileURLWithPath:] + 90
5   Foundation                          0x007e3a44 +[NSURL(NSURL) fileURLWithPath:] + 72
6   SeniorProject                       0x000105f4 -[Video viewDidLoad] + 420
7   UIKit                               0x000ef089 -[UIViewController view] + 179
8   UIKit                               0x000ed482 -[UIViewController contentScrollView] + 42
9   UIKit                               0x000fdf25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
10  UIKit                               0x000fc555 -[UINavigationController _layoutViewController:] + 43
11  UIKit                               0x000fd870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
12  UIKit                               0x000f832a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
13  UIKit                               0x000ff562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
14  UIKit                               0x000f81c4 -[UINavigationController pushViewController:animated:] + 62
15  SeniorProject                       0x00005998 -[ExerciseList goToVideo:] + 328
16  UIKit                               0x0003f4fd -[UIApplication sendAction:to:from:forEvent:] + 119
17  UIKit                               0x000cf799 -[UIControl sendAction:to:forEvent:] + 67
18  UIKit                               0x000d1c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
19  UIKit                               0x000d07d8 -[UIControl touchesEnded:withEvent:] + 458
20  UIKit                               0x00063ded -[UIWindow _sendTouchesForEvent:] + 567
21  UIKit                               0x00044c37 -[UIApplication sendEvent:] + 447
22  UIKit                               0x00049f2e _UIApplicationHandleEvent + 7576
23  GraphicsServices                    0x011ea992 PurpleEventCallback + 1550
24  CoreFoundation                      0x00f92944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
25  CoreFoundation                      0x00ef2cf7 __CFRunLoopDoSource1 + 215
26  CoreFoundation                      0x00eeff83 __CFRunLoopRun + 979
27  CoreFoundation                      0x00eef840 CFRunLoopRunSpecific + 208
28  CoreFoundation                      0x00eef761 CFRunLoopRunInMode + 97
29  GraphicsServices                    0x011e91c4 GSEventRunModal + 217
30  GraphicsServices                    0x011e9289 GSEventRun + 115
31  UIKit                               0x0004dc93 UIApplicationMain + 1160
32  SeniorProject                       0x00001b39 main + 121
33  SeniorProject                       0x00001ab5 start + 53
)
terminate called after throwing an instance of 'NSException'

【问题讨论】:

  • 如果你得到一个 SIGABRT,那么你在日志中有一些东西。发布。
  • @CodaFi:我马上把它放在编辑中

标签: iphone objective-c nsstring sigabrt nsexception


【解决方案1】:

查看控制台日志,看看它是否显示如下内容:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

如果是,那么sharedManager.vidName肯定和@"vid_name"不一样,无法成功找到路径。也许@“vid_name.mp4”?那么你可能只需要更换

NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:@"mp4"];

NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:nil];

试一试。

【讨论】:

  • 控制台日志确实这么说。我尝试用类型为 nil 的新代码行替换该行,但它仍然不起作用:(
  • 好的。请向我们展示 NSLog(@"'%@'", tempName); 的输出应该有一些平庸的原因,可能是文件名中不必要的空格,或者类似的东西。
  • 我刚刚在上面的日志中添加了NSLog的输出
  • 这看起来不错,不幸的是。我剩下的猜测是:1. tempName 值的末尾有一个不必要的空格,所以用 NSLog(@"+%@+"); 之类的东西检查一下。 2.由于某种原因,实际文件并没有添加到项目中(右侧面板),只是复制到项目文件夹中。
【解决方案2】:

你有没有在错误中看到这一行:

'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

意思是第二个只起作用,因为 iVar 'url' 不像 sharedManager.vidName; 那样不为 NULL,如果你 NSLog 它我可以保证它是 nil。

【讨论】:

  • 您发布了两个版本的 viewDidLoad,不是吗?
  • 哎呀。脑袋放屁。当我 NSLog sharedManager.vidName 时,它​​不是零。正确的字符串保存在 sharedManager.vidName 中。这是你的意思吗?
【解决方案3】:

这是我见过的最晦涩难懂的东西之一……iOS 中的大量内容之一。我对名为 GetLocationVideo.m4v 的文件有同样的问题。我还有其他一些运行良好的文件。其中之一是 MVI_1723.MOV。经过几个小时的工作后,应该花费超过 1 秒的时间。我从 xcode 资源的参考列表中删除了 GetLocationVideo.m4v。我将 GetLocationVideo.m4v 文件重命名为 MVI_1724.MOV,放回 Xcode 的资源文件夹。重新运行该应用程序,它工作正常。看来 xcode 需要具有大写的视频文件扩展名。 .MOV 将起作用。我没有尝试过 .MP4 或任何扩展名。为什么?我不知道。有很多错误或没有任何意义的事情,您必须阅读 10,000 页的文档,甚至不值得尝试了解原因。继续前进,直到下一件大事出现在您面前。我希望这将帮助其他人在同样的路线上挣扎。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多