AudioServicesPlaySystemSound不工作的iPad设备上 [英] AudioServicesPlaySystemSound not working on iPad device

查看:433
本文介绍了AudioServicesPlaySystemSound不工作的iPad设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发我的第一个iPad应用的早期阶段,为了简单起见,我一直在使用AudioServicesPlaySystemSound和相关功能播放声音迄今。我的code是基于苹果的节拍器例如SoundEffect类。

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.

具体的症状是,我能听到的声音在模拟器上而不是设备上,虽然我已经验证了我能听到在设备上的其他应用程序的声音。 AudioServicesCreateSystemSoundID正在返回有效的声音标识符,所以它不是任何简单为具有不同的情况下的声音文件的名称,即,sound.mp3与Sound.mp3。

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".

我承认,我可能需要切换到一个不同的库如OpenAL的不相干的原因,但我想知道是怎么回事。有没有人有什么建议?是否有一个功能,我可以打电话获得OSStatus价值的东西?

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 - 我一直工作在其他项目上,在过去几个星期,但现在我又回来就这个问题和我真的AP preciate一个答案。谢谢你。

* 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.

推荐答案

我不认为你可以使用设备上播放MP3文件 AudioServicesPlaySystemSound 。看看在<一个href=\"http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/SystemSoundServicesReference/Reference/reference.html%23//apple_ref/c/func/AudioServicesPlaySystemSound\"相对=nofollow>文档支持的文件类型。我不知道他们为什么在模拟器中发挥正常,但我有同样的问题。尝试使用AVAudioPlayer来代替:

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];

这篇关于AudioServicesPlaySystemSound不工作的iPad设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆