声音在带有断点的iPhone模拟器中播放,但无法播放没有断点 [英] Sound plays in iphone simulator with breakpoint, but fails to play without breakpoint

查看:149
本文介绍了声音在带有断点的iPhone模拟器中播放,但无法播放没有断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone模拟器中播放声音(使用3.1 SDK)。当我添加一个断点,并通过GDB中的代码,声音播放。

I am trying to get a sound to play in the iPhone Simulator (using 3.1 SDK). When I add a breakpoint, and step through the code in GDB, the sound plays. However, if I disable the breakpoint, the sound does not play.

调用声音的代码是:

SoundEffect *completeSound = [myobj completeSound];
if (completeSound != nil) {
    [completeSound play];
}

SoundEffect类有一个简单的播放方法:

The SoundEffect class has a simple play method:

// Plays the sound associated with a sound effect object.
-(void)play {
    // Calls Core Audio to play the sound for the specified sound ID.
    AudioServicesPlaySystemSound(_soundID);
}



如果我在myobj completeSound方法上启用断点, 。

If I enable a breakpoint above the "myobj completeSound" method, it plays perfectly. However, if there's no breakpoint, no sound is emitted.

音频文件是一个长度为5秒的CAF文件。

The audio file is a CAF file that's 5 seconds in length.

在调用AudioServicesPlaySystemSound以确保它起作用之后,我需要添加一些延迟吗?

Is there some delay that I need to add after invoking AudioServicesPlaySystemSound to ensure that it plays?

更新:似乎使用AudioServicesAddSystemSoundCompletion方法是解决方案

UPDATE: it appears that using the AudioServicesAddSystemSoundCompletion method is the solution.

SoundEffect *completeSound = [myobj completeSound];
if (completeSound != nil) {
    AudioServicesAddSystemSoundCompletion([completeSound _soundID], 
        NULL, NULL, AudioPlaybackComplete, self);
    [completeSound play];
} 

然后AudioPlaybackComplete静态函数在音频剪辑完成时调用。

Then the AudioPlaybackComplete static function is invoked when the audio clip is done. This works properly - although I still do not understand why the audio clip fails in the initial use case.

推荐答案

您是否已经检查过您的程序流?因为它让我相信,没有断点你的程序反复触发播放消息,并重新播放声音多次,这么高的频率,你从来没有听到任何样本的。使用断点,您可以停止代码中断播放。

Have you checked your program flow? Because it leads me to believe that without the breakpoint your program repeatedly fires the play message and restarts the playback of the sound many times with so high frequency you never get to hear any samples of it. With the breakpoint, you halt your code from disrupting the playback.

这篇关于声音在带有断点的iPhone模拟器中播放,但无法播放没有断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆