Note that there are some explanatory texts on larger screens.

plurals
  1. POSound plays in iphone simulator with breakpoint, but fails to play without breakpoint
    text
    copied!<p>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.</p> <p>The code to invoke the sound is:</p> <pre><code>SoundEffect *completeSound = [myobj completeSound]; if (completeSound != nil) { [completeSound play]; } </code></pre> <p>The SoundEffect class has a simple play method:</p> <pre><code>// 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); } </code></pre> <p>If I enable a breakpoint above the "myobj completeSound" method, it plays perfectly. However, if there's no breakpoint, no sound is emitted.</p> <p>The audio file is a CAF file that's 5 seconds in length.</p> <p>Is there some delay that I need to add after invoking AudioServicesPlaySystemSound to ensure that it plays?</p> <p>UPDATE: it appears that using the AudioServicesAddSystemSoundCompletion method is the solution.</p> <pre><code>SoundEffect *completeSound = [myobj completeSound]; if (completeSound != nil) { AudioServicesAddSystemSoundCompletion([completeSound _soundID], NULL, NULL, AudioPlaybackComplete, self); [completeSound play]; } </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload