【问题标题】:App doesn't play sound应用程序不播放声音
【发布时间】:2013-01-18 22:15:41
【问题描述】:

我正在为 iOS 制作一个音板,并使用以下代码:

#import <AVFoundation/AVAudioPlayer.h>

...

 NSString *path = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

theAudio.delegate=self;
[theAudio play];
NSLog(@"Audio Played");

我在日志中看到“已播放音频”,但我什么也没听到。

我会收到这个错误:

 Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:  dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:30.988 Ronald Goedemondt[461:1c03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:  dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:31.051 Ronald Goedemondt[461:1c03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:  dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:31.066 Ronald Goedemondt[461:1c03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:  dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security

谁能帮帮我? 谢谢!

【问题讨论】:

  • 您是否检查了设备上的静音开关?你确定他的路径是有效的吗?你检查AVAudioPlayer 的初始化是否正确?
  • 是的,路径有效...声音在 Sound/Sound-wav/bg.wav 中

标签: ios avfoundation wav


【解决方案1】:

编辑:该错误使这似乎是模拟器尝试在 iOS 5.1 或更低版本上播放声音时发生的已知错误。这不应该在实际设备或 iOS 6.0 模拟器上发生。

在播放音频文件之前,您需要致电[theAudio prepareToPlay]; 这似乎是这里的问题。

#import <AVFoundation/AVAudioPlayer.h>

...

 NSString *path = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

theAudio.delegate=self;
[theAudio prepareToPlay];
[theAudio play];
NSLog(@"Audio Played");

除此之外,您还可以检查音频文件的路径等。

if ((sound_file = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"])
{
     //Audio Stuff
}
else{
     //Error
}

【讨论】:

  • 您添加了[theAudio prepareToPlay]; 吗?
  • 我已经编辑了我的答案。添加[theAudio prepareToPlay];后请尝试使用6.0模拟器/真机
  • 你也尝试了我的第二个建议? (使用 if 语句检查文件是否存在)
【解决方案2】:

请看这里:What does this gdb output mean?

Apple 在 Bug ID# 10555404 下提交了此问题。已在 XCode 4.5、iOS 6.0 中修复

【讨论】:

  • 不知道 4.6,但正如上面链接中的答案所述,即使在 Xcode 版本 4.5 中与 iOS 5.1(或更低版本)模拟器一起使用时,问题仍然存在。所以也许它还没有为模拟器
  • 我使用我的 iPhone 4 和 iOS 6.1。我不会收到任何错误,但什么也听不到
  • 我的音量已打开(静音已关闭)。
猜你喜欢
  • 2015-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多