开发者

iOS audio samples play only on earphone output

I'm developing a program that plays a short sample when a button is pressed. The problem is that it only plays through earphone output and not through the device's speaker. I've tried .wav and .aiff and AVAudioPlayer and SystemSoundID. On the simulator I can hear the sound. I'm using iPod Touch 4th gen. r开发者_StackOverflow社区unning iOS 4.1. Example code:

NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"button" ofType:@"wav"];
NSURL *url = [NSURL fileURLWithPath:soundFile];
AudioServicesCreateSystemSoundID( (CFURLRef)url, &buttonID);
AudioServicesPlaySystemSound( buttonID );

Edit (solution found): I tried with another .wav file and it worked. Odd, because the original .wav's format is supported by iOS.


Sounds like you've solved the issue, but as a heads-up, you should only be using SystemSoundID style playback for user interface related sounds.

If the audio is a key part of your app, you need to set the appropriate AVAudioSession category and use (for example) the AVAudioPlayer playback methods.

Then again, this might not be relevant. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜