nicklockwood / SoundManager

Simple sound and music player class for playing audio on Mac and iPhone
http://www.charcoaldesign.co.uk/source/cocoa#soundmanager
Other
630 stars 126 forks source link

Setting soundVolume to 0 doesn't appear to work #19

Closed ghost closed 9 years ago

ghost commented 9 years ago

This is a great library, thanks! I'm trying to implement a button to toggle all sound effects on/off. I've subclassed SoundManager and called it SoundEffects. However, calling this line doesn't appear to work:

NSInteger volume = [defaults boolForKey:PlayGameSounds] ? 1 : 0;
[SoundEffects sharedManager].soundVolume = volume;

I've stepped through and checked, and the volume is being set to 0. However all sound effects still play. Am I doing something wrong? Could be a subclassing issue?

nicklockwood commented 9 years ago

Subclassing Singletons is tricky. I can't be sure without looking at your implementation, but I suspect that's the problem.

Why do you need to subclass it?

ghost commented 9 years ago

I subclassed it so that I could keep all my sound logic in one place, and add methods to determine which sound effects to play in certain situations. I suppose I could use a category though. But I also created a bunch of pre-initialised Sound instance variables to avoid the delay in loading them in, which I wouldn't be able to do in a category. Perhaps this is unnecessary though?

nicklockwood commented 9 years ago

Hmm, well I can't actually see any reason why your singleton subclass shouldn't work in this case.

Maybe just put a breakpoint in the playSound methods and see if you can work out why the volume isn't being set correctly?

ghost commented 9 years ago

Ah - I'm just calling [mySound play] rather than [self playSound:mySound]. I suspect that's why, as have set the soundVolume for SoundManager, but not for Sound... Thanks for your help!