0

I have a simple set of FMOD actions that each play various sounds separately. The problem comes in that I have a button that stops all the sounds. FMOD crashes my program if we try to stop a sound that isn't playing. Makes sense. But I've decided that there has to be a way to call a simple if statement to find out "if" and only "if" somethings playing, then stop it.

- (IBAction)myButton:(id)sender {


    if "FMOD CHANNEL IS PLAYING" {

        result = fmodChannel->stop();

    }

}

Any help would be appreciated.

Sean Herman
  • 313
  • 2
  • 15
  • I'm guessing that `fmodChannel` is going POOF! on you when the playing stops, because it's not retained. – Hot Licks Sep 11 '12 at 00:29
  • Everything works as it should and I'm retaining it in previous code. The problem arises when I try to stop a non-playing sound. So this IBAction is a "Back to Main Menu" button and I want to set the channel to stop only "if" its playing. I suppose my question is more, how does FMOD do if statements and is there a way to find out what channels are playing and if so stop them? – Sean Herman Sep 11 '12 at 02:43
  • 1
    Maybe the crash report will bring the light here. – A-Live Sep 11 '12 at 06:29
  • Yes, the traceback should show you where the error is actually occurring and give a hint as to its cause. You should post it here. – Hot Licks Sep 11 '12 at 11:30
  • (I think there is some other cause for your error other than the sound simply being done playing. What specific error are you getting?) – Hot Licks Sep 11 '12 at 11:32
  • -1 for not posting the traceback and error message. – Hot Licks Sep 11 '12 at 11:32

1 Answers1

2

I wouldn't say it “makes sense” that FMOD crashes if you call stop on a channel that isn't playing. It's documented to return an error code on failure. Are you sure fmodChannel is still a valid pointer when you call stop?

Anyway, you can try the isPlaying method:

bool isPlaying;
if (fmodChannel->isPlaying(&isPlaying) == FMOD_OK && isPlaying) {
    fmodChannel->stop();
}
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • This worked! Thanks! Is there any way FMOD allows us to use multiple channels in this? Perhaps like - bool isPlaying; if (fmodChannel1,fmodChannel2,fmodChannel3->isPlaying(&isPlaying) == FMOD_OK && isPlaying) { fmodChannel1,fmodChannel2,fmodChannel3->stop(); } – Sean Herman Sep 11 '12 at 15:21
  • Hey @RobMayoff do you by chance have any ideas on the DSP front? looking to solve this too! Let me know man! I'd love the help brother! http://stackoverflow.com/questions/12375347/fmod-stop-or-reset-a-dsp – Sean Herman Sep 11 '12 at 20:51
  • @SeanHerman I have never used FMOD or a DSP. I simply looked at the FMOD documentation to answer this question. – rob mayoff Sep 11 '12 at 22:35