Skip to content

Commit bfa76de

Browse files
committed
refactoring
1 parent 835bdd0 commit bfa76de

File tree

4 files changed

+5
-20
lines changed

4 files changed

+5
-20
lines changed

Sources/swiftui-loop-videoplayer/protocol/helpers/PlayerDelegateProtocol.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,48 @@ public protocol PlayerDelegateProtocol: AnyObject {
1919
/// display errors accordingly.
2020
///
2121
/// - Parameter error: The specific `VPErrors` instance describing what went wrong.
22-
@MainActor
2322
func didReceiveError(_ error: VPErrors)
2423

2524
/// A method that handles the passage of time in the player.
2625
/// - Parameter seconds: The amount of time, in seconds, that has passed.
27-
@MainActor
2826
func didPassedTime(seconds: Double)
2927

3028
/// A method that handles seeking in the player.
3129
/// - Parameters:
3230
/// - value: A Boolean indicating whether the seek was successful.
3331
/// - currentTime: The current time of the player after seeking, in seconds.
34-
@MainActor
3532
func didSeek(value: Bool, currentTime: Double)
3633

3734
/// Called when the player has paused playback.
3835
///
3936
/// This method is triggered when the player's `timeControlStatus` changes to `.paused`.
40-
@MainActor
4137
func didPausePlayback()
4238

4339
/// Called when the player is waiting to play at the specified rate.
4440
///
4541
/// This method is triggered when the player's `timeControlStatus` changes to `.waitingToPlayAtSpecifiedRate`.
46-
@MainActor
4742
func isWaitingToPlay()
4843

4944
/// Called when the player starts or resumes playing.
5045
///
5146
/// This method is triggered when the player's `timeControlStatus` changes to `.playing`.
52-
@MainActor
5347
func didStartPlaying()
5448

5549
/// Called when the current media item in the player changes.
5650
///
5751
/// This method is triggered when the player's `currentItem` is updated to a new `AVPlayerItem`.
5852
/// - Parameter newItem: The new `AVPlayerItem` that the player has switched to, if any.
59-
@MainActor
6053
func currentItemDidChange(to newItem: AVPlayerItem?)
6154

6255
/// Called when the current media item is removed from the player.
6356
///
6457
/// This method is triggered when the player's `currentItem` is set to `nil`, indicating that there is no longer an active media item.
65-
@MainActor
6658
func currentItemWasRemoved()
6759

6860
/// Called when the volume level of the player changes.
6961
///
7062
/// This method is triggered when the player's `volume` property changes.
7163
/// - Parameter newVolume: The new volume level, expressed as a float between 0.0 (muted) and 1.0 (maximum volume).
72-
@MainActor
7364
func volumeDidChange(to newVolume: Float)
7465

7566
}

Sources/swiftui-loop-videoplayer/protocol/player/AbstractPlayer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ extension AbstractPlayer{
233233
}
234234

235235
player.seek(to: seekTime){ [weak self] value in
236-
let currentTime = CMTimeGetSeconds(player.currentTime())
237-
self?.delegate?.didSeek(value: value, currentTime: currentTime)
236+
let currentTime = CMTimeGetSeconds(player.currentTime())
237+
self?.delegate?.didSeek(value: value, currentTime: currentTime)
238238
}
239239
}
240240

Sources/swiftui-loop-videoplayer/protocol/player/LoopingPlayerProtocol.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ internal extension LoopingPlayerProtocol {
125125
if let timePublishing{
126126
timeObserver = player.addPeriodicTimeObserver(forInterval: timePublishing, queue: .main) { [weak self] time in
127127
guard let self = self else{ return }
128-
129-
self.delegate?.didPassedTime(seconds: time.seconds)
128+
DispatchQueue.main.async {
129+
self.delegate?.didPassedTime(seconds: time.seconds)
130+
}
130131
}
131132
}
132133
}

Sources/swiftui-loop-videoplayer/view/helpers/PlayerCoordinator.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import SwiftUI
99
import Combine
1010
import AVFoundation
1111

12-
@MainActor
1312
internal class PlayerCoordinator: NSObject, PlayerDelegateProtocol {
1413

1514
let eventPublisher: PassthroughSubject<PlayerEvent, Never>
@@ -77,23 +76,20 @@ internal class PlayerCoordinator: NSObject, PlayerDelegateProtocol {
7776
/// Called when the player has paused playback.
7877
///
7978
/// This method is triggered when the player's `timeControlStatus` changes to `.paused`.
80-
@MainActor
8179
func didPausePlayback(){
8280
eventPublisher.send(.paused)
8381
}
8482

8583
/// Called when the player is waiting to play at the specified rate.
8684
///
8785
/// This method is triggered when the player's `timeControlStatus` changes to `.waitingToPlayAtSpecifiedRate`.
88-
@MainActor
8986
func isWaitingToPlay(){
9087
eventPublisher.send(.waitingToPlayAtSpecifiedRate)
9188
}
9289

9390
/// Called when the player starts or resumes playing.
9491
///
9592
/// This method is triggered when the player's `timeControlStatus` changes to `.playing`.
96-
@MainActor
9793
func didStartPlaying(){
9894
eventPublisher.send(.playing)
9995
}
@@ -102,15 +98,13 @@ internal class PlayerCoordinator: NSObject, PlayerDelegateProtocol {
10298
///
10399
/// This method is triggered when the player's `currentItem` is updated to a new `AVPlayerItem`.
104100
/// - Parameter newItem: The new `AVPlayerItem` that the player has switched to, if any.
105-
@MainActor
106101
func currentItemDidChange(to newItem: AVPlayerItem?){
107102
eventPublisher.send(.currentItemChanged(newItem: newItem))
108103
}
109104

110105
/// Called when the current media item is removed from the player.
111106
///
112107
/// This method is triggered when the player's `currentItem` is set to `nil`, indicating that there is no longer an active media item.
113-
@MainActor
114108
func currentItemWasRemoved(){
115109
eventPublisher.send(.currentItemRemoved)
116110
}
@@ -119,7 +113,6 @@ internal class PlayerCoordinator: NSObject, PlayerDelegateProtocol {
119113
///
120114
/// This method is triggered when the player's `volume` property changes.
121115
/// - Parameter newVolume: The new volume level, expressed as a float between 0.0 (muted) and 1.0 (maximum volume).
122-
@MainActor
123116
func volumeDidChange(to newVolume: Float){
124117
eventPublisher.send(.volumeChanged(newVolume: newVolume))
125118
}

0 commit comments

Comments
 (0)