【问题标题】:Weird error while trying to play .mp3 sound effects in xcode?尝试在 xcode 中播放 .mp3 音效时出现奇怪的错误?
【发布时间】:2013-05-21 13:10:11
【问题描述】:

我正在尝试在 xcode 中编写最简单的“按下按钮并听到声音”设置,但我仍然设法得到一些神秘的错误。这是我的代码:

在 .h 文件中:

#import <AVFoundation/AVFoundation.h>

在 .m 文件中:

- (IBAction)beepButton:(UIButton *)sender {
       NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                   pathForResource:@"buttonBeep"
                                                   ofType:@"mp3"]];
        AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
        [click play];
    //[click release];
}

当我尝试编译我的应用程序时,我得到了错误:

Undefined symbols for architecture armv7s:
  "_OBJC_CLASS_$_AVAudioPlayer", referenced from:
      objc-class-ref in MyFirstViewController.o
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我做错了吗?任何帮助表示赞赏!

【问题讨论】:

  • 您是否已将它们添加到您的框架中?
  • 您是否在项目中添加了 AVFoundation.framework?

标签: ios avaudioplayer linker-errors


【解决方案1】:

这称为链接器错误。这是在一切都编译好之后完成的。

问题在于符号_OBJC_CLASS_$_AVAudioPlayer。您所做的是忽略美元符号上方的部分,留下AVAudioPlayer

由于您尝试使用AVAudioPlayer 类并导入&lt;AVFoundation/AVFoundation.h&gt;,您需要意识到您必须在项目中包含AVFoundation.framework

如果您查看AVAudioPlayer 的参考文档,您会看到文档声明它在AVFoundation.framework 中。这就是您知道需要将其添加到项目中的方式。

【讨论】:

  • 非常彻底,帮助我理解了错误的原因,而不是仅仅调试这个特定的代码。谢谢!
【解决方案2】:

您必须将AVFoundation.framework 添加到您的项目中,因为它包含AVAudioPlayer

【讨论】:

    【解决方案3】:

    你添加了 AVFoundation.framework 了吗?并确保您的 .mp3 文件出现在“复制捆绑资源”中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多