0

アプリのビューに somoe ボタンがあり、ユーザーが 1 つのボタンをクリックするとサウンドが再生されます。アプリの設定ビューにスイッチを追加したいのですが、ユーザーがスイッチを閉じると、ユーザーがボタンをクリックしてもサウンドが再生されません。その後、スイッチをオンにすると、再びサウンドが再生されます。私は何をすべきか?前もって感謝します!

4

2 に答える 2

2
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
if ([switch isOn]){
   [musicPlayer setVolume:1.0];
} else {
    [musicPlayer setVolume:0.0];
}

お役に立てれば。

于 2012-06-06T07:40:56.160 に答える
1

One option is to route all sound playback through a single class and add a property to this class for muting or sound skipping:

@interface Jukebox : NSObject
@property(assign, getter=isMuted) BOOL muted;
- (void) playSoundWithID: (NSString) soundID;
@end

@implementation Jukebox
@synthesize muted;

- (void) playSoundWithID: (NSString) soundID
{
    if (!muted) {
        // …
    }
}

@end

Or you can wrap AVAudioPlayer and make it check some app-wide boolean flag before playing:

@implementation CustomAudioPlayer

- (BOOL) play
{
    return ([[AppSettings sharedInstance] playSounds]) ?
        [super play] : NO;
}
于 2012-06-06T07:58:18.290 に答える