0

我是 iPhone 开发的初学者。我要播放声音。所以,这就是我应用此代码的原因

(void)viewDidLoad
{
    NSError* err;
    path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
    dict=[NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *animalaudio=[dict valueForKey:@"audio"];
    NSString *audiolist=[animalaudio objectAtIndex:currentsound];
    AVAudioPlayer *audio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL    fileURLWithPath:audiolist error:&err]];
    audio.delegate=self;
    [audio play];

}

我得到了运行时错误

[NSURL fileURLWithPath:error:]: unrecognized selector sent to class 0x182121c
2012-07-14 14:51:21.711 plistdemo[1236:10703] *** Terminating app due to uncaught 
exception 'NSInvalidArgumentException', reason: '+[NSURL fileURLWithPath:error:]:     
unrecognized selector sent to class 0x182121c'
terminate called throwing an exceptionsharedlibrary apply-load-rules all

所以,给出适用于我的代码的任何建议和源代码

4

1 回答 1

1

NSURL 的当前文档没有列出任何此类方法,例如 'fileURLWithPath:error:'... 似乎已弃用或不正确。

而是尝试使用类似的东西:

[NSURL fileURLWithPath:audioList]

希望能帮助到你...

于 2012-07-14T09:54:01.277 回答