PDA

View Full Version : Sound PlayBack




Moon013
Jan 6, 2009, 10:25 PM
Hi, I am quite new to this, so guess there's where the problem is.

Okay, I got an app which has a looping background music, and upon exit game, the music will stop. And goes into game again, the background should start playing again. The problem is it won't start playing the 2nd time it goes into game. Thats how i do it:

(I use the crash landing soundEngine)

<I load the sound in my init>

SoundEngine_Initialize(44100);
SoundEngine_SetListenerPosition(0.0, 0.0, 1.0);

//SoundEngine_LoadBackgroundMusicTrack([[bundle pathForResource:@"levelOne" ofType:@"mp3"] UTF8String], NO, YES);

<play the sound upon clicking playGame>
SoundEngine_StartBackgroundMusic();

<Stop the sound upon exit>
SoundEngine_StopBackgroundMusic(NO);

Am i missing out something? Sound played for the first time only. I tried putting the loading of the sound in the playGame function; load and play the background music. This actually enables the sound to playback when clicking playGame the 2nd time. But somehow it produces a bit of a delay in iPhone to start the game because of this. What i wanted is actually load once, and able to toggle between play and stop throughout. Need desperate help, thanks in advance.



CommanderData
Jan 7, 2009, 07:15 AM
I know that SoundEngine uses POSIX threads... not sure if you're properly handling the second thread? Is it joinable? If so, are you joining back up before termination (pthread_join)? Finally, are you absolutely sure that stopmusic is executing?

Moon013
Jan 9, 2009, 12:48 AM
I am sure stop music is executing. The music stopped when code executed. Regarding the threads, I don't know anything about it unfortunately...I didn't touched any threads handling stuff..

CommanderData
Jan 9, 2009, 07:24 AM
I am sure stop music is executing. The music stopped when code executed. Regarding the threads, I don't know anything about it unfortunately...I didn't touched any threads handling stuff..

Now, that's not exactly what you said. You said that *when the game is exited* the music stops playing. That does not actually mean that your stop music call is executing. Have you verified that by adding NSLog statements to the beginning and end of the stop music code to make sure it's fully executing? I'm curious to know if that thread is getting lost and left in memory when your main app terminates...

Moon013
Jan 27, 2009, 08:09 PM
I did a printf and I am sure its being called. However, there is a error message when that particular stop function is called:

Error enqueuing new buffer: -66632

Guess something's not right :confused: