在模拟器上发出声音但不是设备

use*_*949 6 iphone cocoa-touch core-audio

我正在使用以下内容播放m4a文件:

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: fileName];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
Run Code Online (Sandbox Code Playgroud)

它在模拟器上工作正常,但我在设备上没有听到任何声音.我正在使用的声音文件都留在捆绑中.以下是来自设备的filePath:

file://localhost/var/mobile/Applications/418945F3-3711-4B4D-BC65-0D78993C77FB/African%20Adventure.app/Switch%201.m4a
Run Code Online (Sandbox Code Playgroud)

是否存在文件路径问题或我需要为设备做的任何不同的事情?

pch*_*10k 5

我也遇到了麻烦.最后我意识到这是因为AudioServices只能播放具有以下constratints的音频.

使用此功能播放的声音文件必须: - 持续时间不超过30秒 - 采用线性PCM或IMA4(IMA/ADPCM)格式 - 打包在.caf,.aif或.wav文件中

来自Apple文档:http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/SystemSoundServicesReference/Reference/reference.html


The*_*n24 5

就像一个旁注 - 我遇到了完全相同的问题,花了大约一个小时将文件转换成正确的格式等等.但问题是iPad上的"静音"开关.所以尽管音量很高,我可以在iPad上听到其他声音,因为静音开关已打开,但它没有播放系统声音.

为了增加混乱,这个应用程序使用文本到语音,来自听写的音量非常好,只有来自AudioServicesPlaySystemSound()的声音没有被播放.


Rob*_*ier 0

首先对您的退货进行错误检查。filePath 是否为零?AudioServices 函数是否返回错误?最可能的原因是区分大小写。iPhone 文件系统区分大小写,而 Mac 则不区分大小写。但调试的第一步是查看系统提供的错误。