【问题标题】:iphone simulator 3.2 AvAudioPlayer fileURL Issueiphone 模拟器 3.2 AvAudioPlayer fileURL 问题
【发布时间】:2011-06-28 04:19:59
【问题描述】:

我在使用 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 框架,以使其与 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'

我该如何解决?

【问题讨论】:

    标签: ios-simulator avaudioplayer filepath ios3.0


    【解决方案1】:

    资源的名称不应该有扩展名,你的应该只叫@"1"

    【讨论】:

      【解决方案2】:

      查看错误信息

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

      ,因此您可能需要暂停

      NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name ofType:@"mp3"];

      po appDelegate.globalMP3Name 看看会发生什么。

      我认为它只是零。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        • 2021-04-12
        • 1970-01-01
        • 2011-02-13
        • 1970-01-01
        • 2011-02-12
        相关资源
        最近更新 更多