【问题标题】:Obj C just play mp3Obj C 只播放 mp3
【发布时间】:2011-05-10 01:02:53
【问题描述】:

我在至少三个教程中看到过这段小代码,当我按下连接到我得到的操作的按钮时:

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

它说我的路径是空的,它是根据控制台。关于我缺少什么的任何想法?

-(IBAction) pushStart
{
    NSString *arrowSoundPath = [[NSBundle mainBundle] pathForResource:@"Arrow.mp3" ofType:@"mp3"];
    NSLog(@"%@",arrowSoundPath);
    AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:arrowSoundPath] error:NULL];
    theAudio.delegate = self;
    [theAudio play];
}

【问题讨论】:

    标签: iphone objective-c audio mp3


    【解决方案1】:

    从第一个参数中删除“.mp3”扩展名到-pathForResource:ofType:。应该是[[NSBundle mainBundle] pathForResource:@"Arrow" ofType:@"mp3"]。您现在拥有它的方式,-pathForResource:ofType: 正在寻找一个名为“Arrow.mp3.mp3”的文件,该文件不存在,因此它返回 nil,这导致了您的错误。

    【讨论】:

    • 很高兴能帮上忙,似乎总是最让我慢下来的小事......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    相关资源
    最近更新 更多