【发布时间】:2012-09-19 15:49:24
【问题描述】:
我正在尝试使用 AVFoundation 框架播放 mp3 文件。它无法检测到文件并出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
实现的代码:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
NSLog(@"directory %@",path);
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
当我将 pathForResource:@"sound" 更改为 pathForResource:@"sound" (空格)时,它可以检测到文件但听不到声音。我也在 .h 文件中声明了 AVdelegate。有谁知道是什么问题?
【问题讨论】:
-
您的设备静音了吗?这比你想象的要多。
-
stackoverflow.com/questions/4640880/… stackoverflow.com/questions/8016765/… 这两个链接解决了这个问题。还是很感激
标签: ios xcode audio avfoundation