0

如果我在 XCODE 中使用 OALSimpleAudio 在“touch down”上循环播放声音,并希望在“touch up”时停止该音频,那么代码看起来如何?我试过“stopBg”方法——但这会停止我所有的声音,而且我有多个声音在运行,我只希望它停止“sample001”。任何帮助将不胜感激!谢谢!

-(IBAction)sample001Touch {

[[OALSimpleAudio sharedInstance] playEffect:sample001 loop:TRUE];

}

-(IBAction)sample001Release {

NSLog(@"Stop Please");

}

4

1 回答 1

1

根据http://kstenerud.github.com/ObjectAL-for-iPhone/documentation/interface_o_a_l_simple_audio.html

-(id < ALSoundSource > )playEffect:loop: 返回id< ALSoundSource >,并且根据http://kstenerud.github.com/ObjectAL-for-iPhone/documentation/protocol_a_l_sound_source-p.html ALSoundSource 已经停止。只需保存参考,然后您就可以停止它:

@property (nonatomic, strong) id<ALSoundSource> source;

--

- (IBAction)sample001Touch {
    self.source = [[OALSimpleAudio sharedInstance] playEffect:sample001 loop:YES];
}

-(IBAction)sample001Release {
    [self.source stop];
    self.source = nil;
}
于 2013-01-02T20:06:03.850 回答