【问题标题】:Error when trying to use AVAudioPlayer尝试使用 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"];
  • 好的...没有错误...但也没有声音
  • 这工作“AudioServicesPlaySystemSound(1005);”但仍然无法让 AVAudioPlayer 工作

标签: objective-c avaudioplayer


【解决方案1】:

您需要为 AVFoundation 添加框架。

【讨论】:

    猜你喜欢
    • 2017-07-18
    • 2017-02-08
    • 2018-12-02
    • 2020-09-07
    • 2021-09-14
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多