1

您好,我正在使用以下代码片段。

NSString *path = [[NSBundle mainBundle]pathForResource:@"mtgcko" ofType:@"caf"];
    [audioPlayer initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    audioPlayer.delegate = self;
    [audioPlayer play]; 

它应该可以工作,但在我的设备和模拟器上我收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 但是我在 NSURL 中调用的文件存在于 MainBundle 中。

不知道问题出在哪里。我在网上的一些文章中读到问题可能出在编解码器中?但这似乎不是,因为我可以播放所有其他格式,包括 aiif、mp3、wav ......

4

0 回答 0