Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit ae11dfc

Browse files
author
zouzelong
committed
chore: add audio mute support
1 parent 576ee5c commit ae11dfc

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Source/SVGAPlayer+public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef void(^SVGAPlayerDynamicDrawingBlock)(CALayer *contentLayer, NSInteger fr
3232
@property (nonatomic, assign) IBInspectable BOOL clearsAfterStop;
3333
@property (nonatomic, copy) NSString *fillMode;
3434
@property (nonatomic, copy) NSRunLoopMode mainRunLoopMode;
35+
@property (nonatomic, assign) BOOL mute;
3536

3637
- (void)startAnimation;
3738
- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse;

Source/SVGAPlayer.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ - (void)clearAudios {
160160
}
161161
}
162162

163+
- (void)setAudiosVolums:(float)volume {
164+
for (SVGAAudioLayer *layer in self.audioLayers) {
165+
if (layer.audioPlaying) {
166+
[layer.audioPlayer setVolume:volume];
167+
}
168+
}
169+
}
170+
171+
- (void)setMute:(BOOL)mute {
172+
if (_mute != mute) {
173+
_mute = mute;
174+
if (mute) {
175+
[self setAudiosVolums:0.0];
176+
}else {
177+
[self setAudiosVolums:1.0];
178+
}
179+
}
180+
}
181+
163182
- (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay {
164183
if (self.videoItem == nil) {
165184
NSLog(@"videoItem could not be nil!");
@@ -356,6 +375,11 @@ - (void)update {
356375
for (SVGAAudioLayer *layer in self.audioLayers) {
357376
if (!layer.audioPlaying && layer.audioItem.startFrame <= self.currentFrame && self.currentFrame <= layer.audioItem.endFrame) {
358377
[layer.audioPlayer setCurrentTime:(NSTimeInterval)(layer.audioItem.startTime / 1000)];
378+
if (self.mute) {
379+
[layer.audioPlayer setVolume:0.0];
380+
}else {
381+
[layer.audioPlayer setVolume:1.0];
382+
}
359383
[layer.audioPlayer play];
360384
layer.audioPlaying = YES;
361385
}

0 commit comments

Comments
 (0)