0

我做了很多努力才能让它发挥作用。我试图解释。我有这样的声音:

看这里

我使用以下方法从代码的任何地方播放声音:

[PlaySounds PlaySound:glo_sound_login];

这将是这部分代码

+(void)PlaySound:(NSString *)PlaySound{
    SystemSoundID soundID;
NSString *soundFile = [[NSBundle
                        mainBundle]pathForResource:PlaySound ofType:@"mp3"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL
                                            fileURLWithPath:soundFile],&soundID);
AudioServicesPlaySystemSound(soundID);
if (glo_pref_vibrate == YES) {
    AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);}}

所以我的 glo_sound_login 看起来像这样:NSString *glo_sound_login=@"Login";

这工作得很好。但是当我尝试打电话时

[PlaySounds PlaySound:glo_sound_update];

看起来像这样:NSString *glo_sound_update=@"Update";

然后它不会播放我的更新声音!有没有解释为什么我不会播放我的声音?对于任何帮助,我都表示感谢!:) 谢谢还有一件事:当我尝试点击 Update.mp3 文件时,xcode 会打开该文件并播放: 请参见此处

4

1 回答 1

0

According to the documentation about AudioServicesPlaySystemSound function, you cannot use a mp3 format in that context.

Full documentation here

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

Notice: use afconvert to easily create right format files.

example to generate a CAF file / little-endian 16bit (should be perfect).

/usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}
于 2013-03-11T20:28:15.127 回答