diff --git a/SpriteBuilder/ccBuilder/AnimationPlaybackManager.m b/SpriteBuilder/ccBuilder/AnimationPlaybackManager.m index 1a4bbe72b..c5938fe16 100644 --- a/SpriteBuilder/ccBuilder/AnimationPlaybackManager.m +++ b/SpriteBuilder/ccBuilder/AnimationPlaybackManager.m @@ -94,12 +94,17 @@ - (IBAction)play:(id)sender // Start playback self.playbackLastFrameTime = [NSDate timeIntervalSinceReferenceDate]; self.playingBack = YES; + + // playing sound effects at current position + //[_sequencerHandler.currentSequence playSoundEffectsAtPosition:_sequencerHandler.currentSequence.timelinePosition]; + [self updatePlayback]; } - (IBAction)stop { self.playingBack = NO; + [[OALSimpleAudio sharedInstance] stopAllEffects]; } - (IBAction)jumpToStart:(id)sender diff --git a/SpriteBuilder/ccBuilder/SequencerSequence.h b/SpriteBuilder/ccBuilder/SequencerSequence.h index 2103dc81f..1f721b989 100644 --- a/SpriteBuilder/ccBuilder/SequencerSequence.h +++ b/SpriteBuilder/ccBuilder/SequencerSequence.h @@ -30,6 +30,8 @@ @class SequencerCallbackChannel; @class SequencerSoundChannel; +//@class AVPlayer, AVPlayerLayer; + @interface SequencerSequence : NSObject { float timelineScale; @@ -37,6 +39,7 @@ float timelineLength; float timelinePosition; float timelineResolution; + //AVPlayer *soundPlayer; NSString* name; int sequenceId; @@ -86,4 +89,6 @@ - (float) alignTimeToResolution:(float)time; +-(void)playSoundEffectsAtPosition:(NSTimeInterval) timelinePositionForSound; + @end diff --git a/SpriteBuilder/ccBuilder/SequencerSequence.m b/SpriteBuilder/ccBuilder/SequencerSequence.m index 98e990726..4e918c0df 100644 --- a/SpriteBuilder/ccBuilder/SequencerSequence.m +++ b/SpriteBuilder/ccBuilder/SequencerSequence.m @@ -68,6 +68,7 @@ - (id) init callbackChannel = [[SequencerCallbackChannel alloc] init]; soundChannel = [[SequencerSoundChannel alloc] init]; + //soundPlayer = [[AVPlayer alloc] init]; return self; } @@ -93,6 +94,7 @@ - (id) initWithSerialization:(id)ser callbackChannel = [[SequencerCallbackChannel alloc] initWithSerialization: serCallbacks]; id serSounds = [ser objectForKey:@"soundChannel"]; soundChannel = [[SequencerSoundChannel alloc] initWithSerialization: serSounds]; + //soundPlayer = [[AVPlayer alloc] init]; return self; } @@ -253,6 +255,14 @@ - (void) stepForward:(int)numSteps if ([[NSFileManager defaultManager] fileExistsAtPath:absFile]) { [[OALSimpleAudio sharedInstance] playEffect:absFile volume:gain pitch:pitch pan:pan loop:NO]; + + /* + NSURL *url = [[NSURL alloc] initFileURLWithPath: absFile]; + AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; + AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset]; + [soundPlayer initWithPlayerItem:anItem]; + [soundPlayer play]; + */ } } @@ -261,6 +271,30 @@ - (void) stepForward:(int)numSteps [[SequencerHandler sharedHandler] updateScrollerToShowCurrentTime]; } +-(void)playSoundEffectsAtPosition:(NSTimeInterval) timelinePositionForSound +{ + /* + // search previous keys for music, and seek to the correct position if not already started + NSArray* soundKeyframes = [soundChannel.seqNodeProp keyframesBetweenMinTime:0 maxTime:timelinePositionForSound]; + for (SequencerKeyframe* keyframe in soundKeyframes) + { + NSString* soundFile = [keyframe.value objectAtIndex:0]; + float pitch = [[keyframe.value objectAtIndex:1] floatValue]; + float pan = [[keyframe.value objectAtIndex:2] floatValue]; + float gain = [[keyframe.value objectAtIndex:3] floatValue]; + + NSString* absFile = [[ResourceManager sharedManager] toAbsolutePath:soundFile]; + if ([[NSFileManager defaultManager] fileExistsAtPath:absFile]) + { + // typedef double NSTimeInterval; (seconds) + // SequencerHandler* sh = [SequencerHandler sharedHandler]; + [[OALSimpleAudio sharedInstance] preloadBg:absFile seekTime:timelinePositionForSound]; + [[OALSimpleAudio sharedInstance] playEffect:absFile volume:gain pitch:pitch pan:pan loop:NO]; + } + } + */ +} + - (void) stepBack:(int)numSteps { float newTime = [self alignTimeToResolution: timelinePosition - numSteps/timelineResolution];