AudioServicesPlaySystemSound not playing sounds

后端 未结 6 1739
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 14:44

I am playing a small .wav file using the AudioToolBox.

AudioServicesPlaySystemSound (soundFileObject);

But sometimes it is not playing.

6条回答
  •  醉酒成梦
    2021-02-20 15:31

    Building on user1056521's answer, use the following code:

    AudioServicesPlaySystemSoundWithCompletion(soundID, ^{
        AudioServicesDisposeSystemSoundID(soundID);
    });
    

    where soundID is the SystemSoundID value you got when you called AudioServicesCreateSystemSoundID().

    The completion block ensures the sound was played and completed playing before it is disposed of.

提交回复
热议问题