iphone模拟器3.2 AvAudioPlayer fileURL问题
我在使用 avaudioPlayer 时遇到了一个奇怪的问题。当我运行 iphone 模拟器 4.0、4.1 和 4.2 时,它工作正常。当我运行 ipad 模拟器 4.2 时它也工作正常,但是当我运行 ipad 模拟器 3.2 时它会崩溃,因为 AVAudioPlayer 代码的 fileURL 为 Null。
这是我的代码。
NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name
ofType:@"mp3"];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
我正在使用带有弱链接的 AVFoundation Framework 来使其兼容 iOS3。它正确获取 globalMP3Name (1.mp3),因此 1.mp3 的 filePath 不应为空。 FileURL 可以与其他模拟器配合使用,但只有 3.2 崩溃。
这是来自控制台的错误消息。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter'
2011-06-27 18:51:57.092 Stack: (
45475920,
46633772,
45213451,
45213290,
1135303,
18960,
3038446,
3535934,
3545280,
3540077,
3165672,
3057219,
3088856,
53191036,
44755100,
44751016,
53184669,
53184866,
3081074,
10148,
10037
)
terminate called after throwing an instance of 'NSException'
我该如何修复它?
I am getting a weird problem with avaudioPlayer. It work fine when I run iphone simulator 4.0, 4.1 and 4.2. It also works fine when I run ipad simulator 4.2 but when I run ipad simulator 3.2 then it crashes because AVAudioPlayer code has a fileURL which is Null.
Here is my code.
NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name
ofType:@"mp3"];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
I am using AVFoundation Framework with weak link for making it iOS3 compatible. it is getting globalMP3Name (1.mp3) correctly so filePath of 1.mp3 should not be null. FileURL is working with other simulators but only 3.2 is crashing.
Here is the error msg from console.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter'
2011-06-27 18:51:57.092 Stack: (
45475920,
46633772,
45213451,
45213290,
1135303,
18960,
3038446,
3535934,
3545280,
3540077,
3165672,
3057219,
3088856,
53191036,
44755100,
44751016,
53184669,
53184866,
3081074,
10148,
10037
)
terminate called after throwing an instance of 'NSException'
How do I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
资源的名称不应具有扩展名,您的资源名称应仅名为@“1”
The name of the resource shouldn't have the extension, yours should be called only @"1"
查看错误消息
reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter
,因此您可能需要在
NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate. globalMP3Name ofType:@"mp3"];
po appDelegate.globalMP3Name 看看会发生什么。
我认为这只是零。
Look the error message
reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter
, so you may want pause at
NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name ofType:@"mp3"];
po appDelegate.globalMP3Name to see what happen.
I think it just is nil.