简体   繁体   English

系统声音在iPhone模拟器中播放,但在iPhone上无法播放

[英]System Sound plays in iPhone simulator but on iphone not playing

I want to play a system sound on my iphone, the sound plays very well in the simulator but on the device doesn't work. 我想在iPhone上播放系统声音,该声音在模拟器中播放得很好,但是在设备上无法正常工作。

- (IBAction)SystemSound:(id)sender {
    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"waterfall"      ofType:@"caf"];
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundFileURL, &systemSound);
    AudioServicesPlaySystemSound(systemSound);
}

Couple other things to check before chasing the code issues listed above: 在追逐上面列出的代码问题之前,还需要检查其他事项:

1) Is your phone paired with a Bluetooth headset? 1)您的手机是否已与蓝牙耳机配对? If so, the audio will come out there instead of your external speaker. 如果是这样,音频将在那里而不是外部扬声器发出。

2) Is your audio muted? 2)您的音频静音了吗? Check the switch on the side and your settings. 检查侧面的开关和您的设置。

Here's a small detail that many developers have wasted hours upon: 这是许多开发人员浪费时间的一个小细节:

Case Sensitivity 区分大小写

Really, it all boils down to: 确实,这全部归结为:

  • iPhone Simulator : Case- Insensitive iPhone 模拟器区分大小写
  • iOS device : Case- Sensitive iOS 设备 :区分大小写

So, you might have 'waterfall' in your code, but the actual sound name is 'Waterfall'. 因此,您的代码中可能包含“瀑布”,但实际的声音名称是“瀑布”。 It might even be something like 'wAtErFaLl'. 它甚至可能类似于“ wAtErFaLl”。

This will work fine on the simulator, but not on the device - the device simply won't find the sound. 这可以在模拟器上正常工作,但不能在设备上正常工作-该设备根本找不到声音。

This has happened to me for everything from sounds to images to plists. 从声音到图像再到塑琴师,这一切都发生在我身上。

Check your Cases! 检查您的案例!

Also, AudioServices has some guidelines on what can play in the device and what can't: 此外,AudioServices还提供了有关哪些内容可以在设备中播放以及哪些内容不能播放的准则

Sound files that you play using this function must be: - No longer than 30 seconds in duration - In linear PCM or IMA4 (IMA/ADPCM) format - Packaged in a .caf, .aif, or .wav file 使用此功能播放的声音文件必须为:-持续时间不超过30秒 -线性PCM或IMA4(IMA / ADPCM)格式- 打包为.caf,.aif或.wav文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM