我为我的Mac写了一个廉价而欢快的声板,我用NSSound播放各种声音:
-(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying { BOOL wasPlaying = FALSE; if([nowPlaying isPlaying]) { [nowPlaying stop]; wasPlaying = TRUE; } if(soundEffect != nowPlaying) { [soundEffect play]; nowPlaying = soundEffect; } else if(soundEffect == nowPlaying && ![nowPlaying isPlaying] && !wasPlaying) { [nowPlaying play]; } }
而不是仅仅停止它,我希望它能在几秒钟内消失.