@@ -37,6 +37,17 @@ public final class ImagePlayer : ObservableObject {
37
37
/// Current playing frame image
38
38
@Published public var currentFrame : PlatformImage ?
39
39
40
+ /// Current playing frame index
41
+ @Published public var currentFrameIndex : UInt = 0
42
+
43
+ /// Current playing loop count
44
+ @Published public var currentLoopCount : UInt = 0
45
+
46
+ /// Current playing status
47
+ public var isPlaying : Bool {
48
+ player? . isPlaying ?? false
49
+ }
50
+
40
51
/// Start the animation
41
52
public func startPlaying( ) {
42
53
player? . startPlaying ( )
@@ -52,38 +63,44 @@ public final class ImagePlayer : ObservableObject {
52
63
player? . stopPlaying ( )
53
64
}
54
65
66
+ /// Seek to frame and loop count
67
+ public func seekToFrame( at: UInt , loopCount: UInt ) {
68
+ player? . seekToFrame ( at: at, loopCount: loopCount)
69
+ }
70
+
55
71
/// Clear the frame buffer
56
72
public func clearFrameBuffer( ) {
57
73
player? . clearFrameBuffer ( )
58
74
}
59
75
60
-
61
76
/// Setup the player using Animated Image
62
77
/// - Parameter image: animated image
63
- public func setupPlayer( image : PlatformImage ? ) {
78
+ public func setupPlayer( animatedImage : SDAnimatedImageProvider ) {
64
79
if player != nil {
65
80
return
66
81
}
67
- if let animatedImage = image as? SDAnimatedImageProvider & PlatformImage {
68
- if let imagePlayer = SDAnimatedImagePlayer ( provider: animatedImage) {
69
- imagePlayer. animationFrameHandler = { [ weak self] ( _, frame) in
70
- self ? . currentFrame = frame
71
- }
72
- // Setup configuration
73
- if let maxBufferSize = maxBufferSize {
74
- imagePlayer. maxBufferSize = maxBufferSize
75
- }
76
- if let customLoopCount = customLoopCount {
77
- imagePlayer. totalLoopCount = customLoopCount
78
- }
79
- imagePlayer. runLoopMode = runLoopMode
80
- imagePlayer. playbackRate = playbackRate
81
- imagePlayer. playbackMode = playbackMode
82
-
83
- self . player = imagePlayer
84
-
85
- imagePlayer. startPlaying ( )
82
+ if let imagePlayer = SDAnimatedImagePlayer ( provider: animatedImage) {
83
+ imagePlayer. animationFrameHandler = { [ weak self] ( index, frame) in
84
+ self ? . currentFrameIndex = index
85
+ self ? . currentFrame = frame
86
+ }
87
+ imagePlayer. animationLoopHandler = { [ weak self] ( loopCount) in
88
+ self ? . currentLoopCount = loopCount
89
+ }
90
+ // Setup configuration
91
+ if let maxBufferSize = maxBufferSize {
92
+ imagePlayer. maxBufferSize = maxBufferSize
93
+ }
94
+ if let customLoopCount = customLoopCount {
95
+ imagePlayer. totalLoopCount = customLoopCount
86
96
}
97
+ imagePlayer. runLoopMode = runLoopMode
98
+ imagePlayer. playbackRate = playbackRate
99
+ imagePlayer. playbackMode = playbackMode
100
+
101
+ self . player = imagePlayer
102
+
103
+ imagePlayer. startPlaying ( )
87
104
}
88
105
}
89
106
}
0 commit comments