AudioServicesPlaySystemSound 在 iPad 设备上不起作用

发布于 2024-09-29 14:24:31 字数 458 浏览 6 评论 0原文

我正处于开发第一个 iPad 应用程序的早期阶段,为了简单起见,我到目前为止一直使用 AudioServicesPlaySystemSound 和相关函数来播放声音。我的代码基于 Apple 的 Metronome 示例中的 SoundEffect 类。

具体症状是我可以在模拟器中听到声音,但在设备上听不到声音,尽管我已经验证可以在设备上的其他应用程序中听到声音。 AudioServicesCreateSystemSoundID 返回有效的声音标识符,因此它并不像具有不同大小写的声音文件名称那么简单,即“sound.mp3”与“Sound.mp3”。

我认识到我可能需要出于不相关的原因切换到不同的库,例如 OpenAL,但我想知道这里发生了什么。有人有什么建议吗?是否有一个函数可以调用来获取 OSStatus 值或其他值?

* BUMP - 过去几周我一直在从事其他项目,但现在我又回到了这个项目,我非常感谢您的回答。谢谢。

I'm in the early stages of developing my first iPad application, and for simplicity I have so far been using AudioServicesPlaySystemSound and the associated functions to play sounds. My code is based the SoundEffect class from Apple's Metronome example.

The specific symptom is that I can hear the sounds in the simulator but not on the device, though I have verified that I can hear sounds in other applications on the device. AudioServicesCreateSystemSoundID is returning valid sound identifiers, so it isn't anything as simple as the name of the sound file having different case, i.e. "sound.mp3" vs. "Sound.mp3".

I recognize that I may need to switch to a different library such as OpenAL for unrelated reasons, but I would like to know what is going on here. Does anyone have any suggestions? Is there a function I can call to get an OSStatus value or something?

* BUMP -- I've been working on other projects for the past few weeks but I'm back on this now and I'd really appreciate an answer. Thanks.

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

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

发布评论

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

评论(2

请帮我爱他 2024-10-06 14:24:31

我通过谷歌搜索发现了这个问题。我的问题正如这个问题的标题所述:“AudioServicesPlaySystemSound 无法在 iPad 设备上工作”。但问题的描述却有所不同。

简而言之,将我的 iPad 升级到 iOS 4.3 后,AudioServicesPlaySystemSound 停止工作。

我终于找到了我的问题版本的解决方案,所以希望这对其他人有帮助。

转到 iPad 上的“设置”应用程序并选择“常规”。点击声音。确保“使用按钮更改”设置为“开”。这将解决这个问题。

I came across this question via a Google search. My problem is exactly as stated in the title of this question: "AudioServicesPlaySystemSound not working on iPad device". However, the description of the issue is different.

Simply put, after upgrading my iPad to iOS 4.3, AudioServicesPlaySystemSound stopped working.

I finally found the solution to my version of the issue, so hopefully this helps someone else.

Go to the Settings app on the iPad and choose General. Tap Sounds. Make sure "Change with Buttons" is set to ON. This will fix the issue.

一影成城 2024-10-06 14:24:31

我认为您无法使用 AudioServicesPlaySystemSound 在设备上播放 mp3 文件。看一下 支持的文件类型的文档。我不确定为什么它们在模拟器中正常播放,但我遇到了同样的问题。尝试使用 AVAudioPlayer 代替:

NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource: @"sound" withExtension: @"mp3"] error:&error];
if (error)  {
    NSLog(@"Error creating audio player: %@", [error userInfo]);
} else {
    [audioPlayer play];
}

[audioPlayer release];

I don't think you can play an mp3 file on the device using AudioServicesPlaySystemSound. Take a look at the documentation for supported file types. I'm not sure why they play correctly in the simulator, but I had the same issue. Try using AVAudioPlayer instead:

NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource: @"sound" withExtension: @"mp3"] error:&error];
if (error)  {
    NSLog(@"Error creating audio player: %@", [error userInfo]);
} else {
    [audioPlayer play];
}

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