Sound PlayBack

Discussion in 'iOS Programming' started by Moon013, Jan 6, 2009.

  1. macrumors newbie

    Jul 14, 2008
    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_SetListenerPosition(0.0, 0.0, 1.0);

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

    <play the sound upon clicking playGame>

    <Stop the sound upon exit>

    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.
  2. macrumors regular

    Dec 1, 2007
    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?
  3. thread starter macrumors newbie

    Jul 14, 2008
    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..
  4. macrumors regular

    Dec 1, 2007
    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...
  5. thread starter macrumors newbie

    Jul 14, 2008
    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:

Share This Page