尝试使用 AVAudioPlayer 时出错
Posted
技术标签:
【中文标题】尝试使用 AVAudioPlayer 时出错【英文标题】:Error when trying to use AVAudioPlayer 【发布时间】:2016-01-02 03:36:55 【问题描述】:以下代码产生以下错误。 不知道为什么?
NSString *soundFilePath = [NSString stringWithFormat:@"%@/abc.m4a",
[[NSBundle mainBundle] resourcePath]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
error:nil];
player.numberOfLoops = -1; //Infinite
[player play];
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_AVAudioPlayer", referenced from:
objc-class-ref in BasicArithmaticViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
【问题讨论】:
需要的框架:/system/library/frameworks/avfoundation.framework 仅供参考 - 不要使用您问题中的代码获取路径。使用NSURL *soundFileURL = [[NSBundle mainBundle] URLForResource:@"abc" withExtension:@"m4a"];
。
好的...没有错误...但也没有声音
试试这个***.com/a/17782212/2522603
这工作“AudioservicesPlaySystemSound(1005);”但仍然无法让 AVAudioPlayer 工作
【参考方案1】:
您需要为 AVFoundation 添加框架。
【讨论】:
以上是关于尝试使用 AVAudioPlayer 时出错的主要内容,如果未能解决你的问题,请参考以下文章
iOS 5.0 AVAudioPlayer 加载音频剪辑时出错:操作无法完成。 (OSStatus 错误 -50。)
iOS:将 AVAudioPlayer 的实例从一个变量移动到另一个变量