代码之家  ›  专栏  ›  技术社区  ›  jowie

在模拟器或设备上听不到系统声音

  •  1
  • jowie  · 技术社区  · 16 年前

    NSString *sndPath = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"aiff"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:sndPath], &soundID);
    AudioServicesPlaySystemSound(soundID);
    AudioServicesDisposeSystemSoundID(soundID);
    

    我已经检查了我的系统首选项,是的,我确实有“播放用户界面音效”勾选。。。我可能做错了什么?

    1 回复  |  直到 16 年前
        1
  •  1
  •   tc.    16 年前

    在声音播放完之前不要处理它。你可以这样做:

    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, (AudioServicesSystemSoundCompletionProc)AudioServicesDisposeSystemSoundID, NULL);
    

    推荐文章