Tuesday, 15 July 2014

ios - Playing sounds in sequence with SimpleAudioEngine -



ios - Playing sounds in sequence with SimpleAudioEngine -

i'm building ios app cocos2d 2, , i'm using simpleaudioengine play effects.

is there way sequence multiple sounds played after previous sound complete?

for illustration in code:

[[simpleaudioengine sharedengine] playeffect:@"yay.wav"]; [[simpleaudioengine sharedengine] playeffect:@"youdidit.wav"];

when code run, yay.wav , youdidit.wav play @ exact same time, on each other.

i want yay.wav play , 1 time complete, youdidit.wav play.

if not simpleaudioengine, there way audiotoolbox, or else?

thank you!

== update ==

i think i'm going go method using 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];

the easy way getting track duration using -[cdsoundsource durationinseconds] , schedule sec effect playing after proper delay:

[[simpleaudioengine sharedengine] performselector:@selector(playeffect:) withobject:@"youdidit.wav" afterdelay:duration];

an easier way sound duration patching simpleaudiomanager , add together method queries cdsoundengine (a static global) sound duration:

- (float)soundduration { homecoming [_engine bufferdurationinseconds:_soundid]; }

the sec approach polling on status of sound engine , wait stop playing.

algetsourcei(sourceid, al_source_state, &state); if (state == al_playing) { ...

the sourceid aluint returned playeffect.

ios audio simpleaudioengine

No comments:

Post a Comment