声音在模拟器中工作,而不是在真实 iPhone 中工作

发布于 2024-08-18 13:20:39 字数 595 浏览 6 评论 0 原文

有一些简短的音效样本,在模拟器中播放得很好,但在真实的iPhone 3GS中根本就不行。以下是来自 Apple SysSound 示例的代码:

CFBundleRef mb = CFBundleGetMainBundle ();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL
    (mb, CFSTR("mySound"), CFSTR ("caf"), NULL);

SystemSoundID sid;
AudioServicesCreateSystemSoundID(soundFileURLRef, &sid);
AudioServicesPlaySystemSound(sid);

使用 iPhone 时,我可以听到按键声和来自 iTunes 的音乐(不尝试在播放声音的同时使用) - 但根本听不到我的声音。 Vibra 工作正常,因此即使是框架也应该正确设置。

甚至尝试了 SoundEffect.h/m 示例代码,没有任何变化。使用相同的声音文件,但 CAF 应该没问题,特别是当它在模拟器中播放时?

接下来我可以尝试什么?

Have few short sound effect samples, which play just fine in emulator, but not at all in real iPhone 3GS. Here's the code, about as-is from Apple SysSound sample:

CFBundleRef mb = CFBundleGetMainBundle ();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL
    (mb, CFSTR("mySound"), CFSTR ("caf"), NULL);

SystemSoundID sid;
AudioServicesCreateSystemSoundID(soundFileURLRef, &sid);
AudioServicesPlaySystemSound(sid);

When using iPhone, I can hear keyclicks and music from iTunes (not trying to use at same time as playing my sound) - but cannot hear my sound at all. Vibra works ok, so even Framework should be set up correctly.

Tried even the SoundEffect.h/m sample code, no change. Used same sound files, but shouldn't CAF be ok, especially when it plays in emulator?

What can I try next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

镜花水月 2024-08-25 13:20:39

尝试转换为其他格式,例如 wav 或 mp3,然后再次播放。如果您想使用 caf,请确保您在 Terminal.app 中正确格式化了 caf:

afconvert -f caff -d ima4 mysound.wav

Try converting to a different format such as wav or mp3, then play again. If you want to use caf, Make sure you are formatting the caf correctly in Terminal.app:

afconvert -f caff -d ima4 mysound.wav
手心的温暖 2024-08-25 13:20:39

作为旁注 - 我遇到了完全相同的问题,并且花了大约一个小时将文件转换为正确的格式等。但问题是 iPad 上的“静音”开关。所以即使音量调大了,我也能听到iPad上的其他声音,但因为静音开关打开了,所以它并没有播放系统声音。

更让人困惑的是,这个应用程序使用文本转语音,并且来自转录的音量非常好,只是来自 AudioServicesPlaySystemSound() 的声音我听不到。

Just as a sidenote - I was having the exact same problem and spent probably close to an hour on converting files to the correct format, etc.. Yet the problem was the "mute" switch on the iPad. So even though the volume was up, and I could hear other sounds on the iPad, because the mute switch was turned on, it wasn't playing system sounds.

To add to the confusion, this app uses text-to-speech and the volume coming from the transcription was perfectly fine, it was only the sounds coming from AudioServicesPlaySystemSound() that I couldn't hear.

霓裳挽歌倾城醉 2024-08-25 13:20:39

有点不太可能,但请记住,手机的文件系统区分大小写,而 Mac 的文件系统通常不区分大小写。仔细检查您的文件名

kind of a long shot, but remember that the phone's file system is case sensitive, while the mac's usually isn't. Double check your file name

娇柔作态 2024-08-25 13:20:39

找到了更简单的解决方案:使用 AIF 声音文件

  • 单击 iTunes >首选项
  • 单击“常规”选项卡
  • 单击“导入设置”按钮
  • 在“导入使用”下拉列表中,选择“AIFF 编码器”
  • 保存更改
  • 选择声音文件并选择“创建 AIFF 版本”

这是我正在使用的代码,以及 Apple 示例的 >SoundEffect.h 和 SoundEffect.m BubbleLevel

NSBundle *mainBundle = [NSBundle mainBundle];
buzzerSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzzerSound" ofType:@"aif"]];
[buzzerSound play];

现在相同的代码 - 和声音效果 - 在模拟器和硬件中工作。顺便说一句,不要忘记切换回原来的 iTunes 设置!

Found an easier solution: use AIF sound files:

  • Click iTunes > Preferences
  • Click on "General" tab
  • Click "Import Settings" button
  • In "Import Using" dropdown, choose "AIFF Encoder"
  • Save your changes
  • Select your sound files and choose "Create AIFF version"

Here's code I'm using, together with SoundEffect.h and SoundEffect.m from Apple sample BubbleLevel:

NSBundle *mainBundle = [NSBundle mainBundle];
buzzerSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzzerSound" ofType:@"aif"]];
[buzzerSound play];

Now same code - and sound effects - work in both emulator and hardware. Btw don't forget to switch back your original iTunes settings!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文