0

音を扱うクラスを作りました。しかし、私は音を止めるのに問題がありますか?playSoundからstopSoundAudioServicesDisposeSystemSoundID(soundID)に変数を送信できません。これをどのように処理しますか?本当にインスタンス化したくないのですか、それともインスタンス化する必要がありますか?

@implementation SoundPlayer
+(void)playSound:(NSString *)filename ofType:(NSString *)extension {
    SystemSoundID soundID;
    NSString *soundFile = [[NSBundle mainBundle] pathForResource:filename ofType:extension];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
    AudioServicesPlaySystemSound(soundID); // error - soundID is undeclared
}

+(void)stopSound
{
    AudioServicesDisposeSystemSoundID(soundID);
}

@end
4

2 に答える 2

1

idをstopSoundに渡す必要があります(サウンドを再生する場合と同じです)。そうでない場合、オーディオプレーヤーが一度に1つのサウンドしか再生しない場合は、再生時にクラスに静的パラメーターとしてsoundIDを保存します。

于 2012-11-22T12:21:32.913 に答える
0

次のように、soundIDをivarとして作成できます。

@interface SoundPlayer(){
     SystemSoundID soundID;
}
@end

他の方法では、グローバル変数として使用します

于 2012-11-22T12:21:57.093 に答える