@@ -31,7 +31,6 @@ @interface SVGAPlayer ()
3131@property (nonatomic , assign ) NSRange currentRange;
3232@property (nonatomic , assign ) BOOL forwardAnimating;
3333@property (nonatomic , assign ) BOOL reversing;
34- @property (nonatomic , assign ) BOOL audioPlaying;
3534
3635@end
3736
@@ -79,8 +78,11 @@ - (void)startAnimation {
7978 }
8079 [self stopAnimation: NO ];
8180 self.loopCount = 0 ;
81+ if (self.videoItem .FPS == 0 ) {
82+ NSLog (@" videoItem FPS could not be 0!" );
83+ return ;
84+ }
8285 self.displayLink = [CADisplayLink displayLinkWithTarget: self selector: @selector (next )];
83-
8486 self.displayLink .frameInterval = 60 / self.videoItem .FPS ;
8587 [self .displayLink addToRunLoop: [NSRunLoop mainRunLoop ] forMode: NSRunLoopCommonModes ];
8688 self.forwardAnimating = !self.reversing ;
@@ -125,13 +127,12 @@ - (void)clear {
125127}
126128
127129- (void )clearAudios {
128- if (!self.audioPlaying ) {
129- return ;
130- }
131130 for (SVGAAudioLayer *layer in self.audioLayers ) {
132- [layer.audioPlayer stop ];
131+ if (layer.audioPlaying ) {
132+ [layer.audioPlayer stop ];
133+ layer.audioPlaying = NO ;
134+ }
133135 }
134- self.audioPlaying = NO ;
135136}
136137
137138- (void )stepToFrame : (NSInteger )frame andPlay : (BOOL )andPlay {
@@ -149,6 +150,10 @@ - (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay {
149150 [self update ];
150151 if (andPlay) {
151152 self.forwardAnimating = YES ;
153+ if (self.videoItem .FPS == 0 ) {
154+ NSLog (@" videoItem FPS could not be 0!" );
155+ return ;
156+ }
152157 self.displayLink = [CADisplayLink displayLinkWithTarget: self selector: @selector (next )];
153158 self.displayLink .frameInterval = 60 / self.videoItem .FPS ;
154159 [self .displayLink addToRunLoop: [NSRunLoop mainRunLoop ] forMode: NSRunLoopCommonModes ];
@@ -324,14 +329,14 @@ - (void)update {
324329 [CATransaction setDisableActions: NO ];
325330 if (self.forwardAnimating && self.audioLayers .count > 0 ) {
326331 for (SVGAAudioLayer *layer in self.audioLayers ) {
327- if (!self .audioPlaying && layer.audioItem .startFrame > = self.currentFrame ) {
332+ if (!layer .audioPlaying && layer.audioItem .startFrame < = self.currentFrame && self. currentFrame <= layer. audioItem . endFrame ) {
328333 [layer.audioPlayer setCurrentTime: (NSTimeInterval )(layer.audioItem.startTime / 1000 )];
329334 [layer.audioPlayer play ];
330- self .audioPlaying = YES ;
335+ layer .audioPlaying = YES ;
331336 }
332- if (self .audioPlaying && layer.audioItem .endFrame <= self.currentFrame ) {
337+ if (layer .audioPlaying && layer.audioItem .endFrame <= self.currentFrame ) {
333338 [layer.audioPlayer stop ];
334- self .audioPlaying = NO ;
339+ layer .audioPlaying = NO ;
335340 }
336341 }
337342 }
0 commit comments