Skip to content

Commit 854ff13

Browse files
committed
Add loading state
1 parent 60fea87 commit 854ff13

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎Sources/Richi/Richi.swift‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct Richi {
1313

1414
/// An enum that describes how the video is displayed within a layer’s bounds rectangle.
1515
public enum Gravity {
16+
1617
/// The player should preserve the video’s aspect ratio and fill the layer’s bounds.
1718
case aspectFill
1819

@@ -25,9 +26,13 @@ public struct Richi {
2526

2627
/// An enum that describes the playback state of the Video Player
2728
public enum PlaybackState: Equatable, CustomStringConvertible {
29+
2830
/// The playback has failed because of the encapsulated error.
2931
case failed(_ error: Richi.Error)
30-
32+
33+
/// The asset is loading
34+
case loading
35+
3136
/// The playback has been paused
3237
case paused
3338

@@ -41,6 +46,8 @@ public struct Richi {
4146
switch self {
4247
case .failed(let error):
4348
return "Failed (\(error))"
49+
case .loading:
50+
return "Loading"
4451
case .paused:
4552
return "Paused"
4653
case .playing:
@@ -52,16 +59,18 @@ public struct Richi {
5259

5360
var isPausable: Bool {
5461
switch self {
55-
case .paused: fallthrough
62+
case .failed(_): return false
63+
case .loading: return false
64+
case .paused: return true
5665
case .playing: return true
57-
case .failed(_): fallthrough
5866
case .stopped: return false
5967
}
6068
}
6169

6270
public static func == (lhs: Richi.PlaybackState, rhs: Richi.PlaybackState) -> Bool {
6371
switch (lhs, rhs) {
6472
case (.failed, .failed): return true
73+
case (.loading, .loading): return true
6574
case (.paused, .paused): return true
6675
case (.playing, .playing): return true
6776
case (.stopped, .stopped): return true

‎Sources/Richi/VideoPlayer+Observers.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extension VideoPlayer {
8888
if playerItem.status == .failed {
8989
self.playbackState = .failed(.playerItemError(playerItem.error))
9090
} else if playerItem.status == .readyToPlay, let asset = self.asset {
91+
self.playbackState = .stopped
9192
self.runOnMainLoop {
9293
self.delegate?.player(self, didLoadAsset: asset)
9394
}

‎Sources/Richi/VideoPlayer.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ extension VideoPlayer {
282282
stop()
283283
}
284284

285-
playbackState = .stopped
285+
playbackState = .loading
286286
pausedReason = .waitKeepUp
287287

288288
updatePlayerItem(nil)

0 commit comments

Comments
 (0)