我正在使用 cocos2d 2 构建一个 iOS 应用程序,并使用 SimpleAudioEngine 来播放一些效果。
有没有办法在前一个声音完成后按顺序播放多个声音?
例如在我的代码中:
[[SimpleAudioEngine sharedEngine] playEffect:@"yay.wav"];
[[SimpleAudioEngine sharedEngine] playEffect:@"youDidIt.wav"];
当这段代码运行时,yay.wav
and youDidIt.wav
完全相同的时间,互相超越。
I want yay.wav
玩并完成后,youDidIt.wav
玩。
如果不使用 SimpleAudioEngine,是否有使用 AudioToolbox 或其他方法的方法?
谢谢你!
== UPDATE ==
我想我将使用 AVFoundation 采用这种方法:
AVPlayerItem *sound1 = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"yay" ofType:@"wav"]]];
AVPlayerItem *sound2 = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"YouDidIt" ofType:@"wav"]]];
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithItems: [NSArray arrayWithObjects:sound1, sound2, nil]];
[player play];
最简单的方法是使用以下命令获取曲目持续时间-[CDSoundSource durationInSeconds]
然后安排在适当的延迟后播放第二个效果:
[[SimpleAudioEngine sharedEngine] performSelector:@selector(playEffect:) withObject:@"youDidIt.wav" afterDelay:duration];
获取音频持续时间的一种更简单的方法是修补 SimpleAudioManager 并添加一个查询其音频的方法CDSoundEngine
(静态全局)音频持续时间:
- (float)soundDuration {
return [_engine bufferDurationInSeconds:_soundId];
}
第二种方法是轮询音频引擎的状态并等待它停止播放。
alGetSourcei(sourceId, AL_SOURCE_STATE, &state);
if (state == AL_PLAYING) {
...
The sourceId
is the ALuint
由返回playEffect
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)