Permalink
Browse files

Fixed sound not playing after load

  • Loading branch information...
1 parent 196c141 commit 20f9fb6f59d02451be7903708ec6b9c0913765cc @phoboslab committed Oct 14, 2012
Showing with 21 additions and 6 deletions.
  1. +2 −1 Classes/Ejecta/EJAudio/EJBindingAudio.h
  2. +19 −5 Classes/Ejecta/EJAudio/EJBindingAudio.m
@@ -26,7 +26,8 @@ static const char * EJAudioPreloadNames[] = {
EJAudioPreload preload;
NSObject<EJAudioSource> * source;
- BOOL loop, ended, loading;
+ BOOL loop, ended;
+ BOOL loading, playAfterLoad;
float volume;
}
@@ -78,9 +78,13 @@ - (void)endLoad:(NSObject<EJAudioSource> *)src {
source = [src retain];
[source setLooping:loop];
[source setVolume:volume];
- [self triggerEvent:@"canplaythrough" argc:0 argv:NULL];
+ if( playAfterLoad ) {
+ [source play];
+ }
loading = NO;
+
+ [self triggerEvent:@"canplaythrough" argc:0 argv:NULL];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
@@ -97,14 +101,24 @@ - (void)setPreload:(EJAudioPreload)preloadp {
EJ_BIND_FUNCTION(play, ctx, argc, argv) {
- [self load];
- [source play];
- ended = false;
+ if( !source ) {
+ playAfterLoad = YES;
+ [self load];
+ }
+ else {
+ [source play];
+ ended = false;
+ }
return NULL;
}
EJ_BIND_FUNCTION(pause, ctx, argc, argv) {
- [source pause];
+ if( !source ) {
+ playAfterLoad = NO;
+ }
+ else {
+ [source pause];
+ }
return NULL;
}

0 comments on commit 20f9fb6

Please sign in to comment.