首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序不播放声音

应用程序不播放声音
EN

Stack Overflow用户
提问于 2013-02-04 16:29:07
回答 2查看 390关注 0票数 1

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

代码语言:javascript
复制
#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");

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

我会得到这个错误:

代码语言:javascript
复制
 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

有谁能帮帮我呢?谢谢!

EN

回答 2

Stack Overflow用户

发布于 2013-02-04 16:32:50

编辑:当模拟器尝试在iOS 5.1或更低版本上播放声音时,该错误使其看起来像是一个已知的错误。这不应该发生在实际的设备或iOS 6.0模拟器上。

在播放音频文件之前,您需要调用[theAudio prepareToPlay];,这似乎是问题所在。

代码语言:javascript
复制
#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");

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

代码语言:javascript
复制
if ((sound_file = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"])
{
     //Audio Stuff
}
else{
     //Error
}
票数 1
EN

Stack Overflow用户

发布于 2013-02-04 16:56:36

查看此处:What does this gdb output mean?

此问题由苹果根据Bug ID# 10555404提交。已在XCode 4.5、iOS 6.0中修复

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14682928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档