Skip to content

Commit

Permalink
A fix for #1
Browse files Browse the repository at this point in the history
Need to find a solution to resume sound at timeline position
  • Loading branch information
oxeron committed Mar 8, 2016
1 parent 3583eae commit 2b7e6a0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SpriteBuilder/ccBuilder/AnimationPlaybackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions SpriteBuilder/ccBuilder/SequencerSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
@class SequencerCallbackChannel;
@class SequencerSoundChannel;

//@class AVPlayer, AVPlayerLayer;

@interface SequencerSequence : NSObject
{
float timelineScale;
float timelineOffset;
float timelineLength;
float timelinePosition;
float timelineResolution;
//AVPlayer *soundPlayer;

NSString* name;
int sequenceId;
Expand Down Expand Up @@ -86,4 +89,6 @@

- (float) alignTimeToResolution:(float)time;

-(void)playSoundEffectsAtPosition:(NSTimeInterval) timelinePositionForSound;

@end
34 changes: 34 additions & 0 deletions SpriteBuilder/ccBuilder/SequencerSequence.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ - (id) init

callbackChannel = [[SequencerCallbackChannel alloc] init];
soundChannel = [[SequencerSoundChannel alloc] init];
//soundPlayer = [[AVPlayer alloc] init];

return self;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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];
*/
}
}

Expand All @@ -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];
Expand Down

0 comments on commit 2b7e6a0

Please sign in to comment.