ios player
autoplay after recycle remove all items from AVPlayer queue recurururururursion use managers in the view add prefetch make sure player items stay in order add controller and item managers start of the view create module, ios
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import AVKit
|
||||
|
||||
class PlayerControllerManager {
|
||||
static let shared = PlayerControllerManager()
|
||||
|
||||
private var controllers: [PlayerController] = []
|
||||
private let max = 10
|
||||
|
||||
func getPlayer() -> PlayerController? {
|
||||
if let controller = self.controllers.first(where: { $0.isInUse == false }) {
|
||||
return controller
|
||||
} else if controllers.count < self.max {
|
||||
let controller = PlayerController()
|
||||
controllers.append(controller)
|
||||
return controller
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func releasePlayer(controller: PlayerController) {
|
||||
if let controller = controllers.first(where: { $0 === controller }) {
|
||||
controller.release()
|
||||
}
|
||||
}
|
||||
|
||||
func findBySource(source: String) -> PlayerController? {
|
||||
if let controller = controllers.first(where: { $0.source == source}) {
|
||||
return controller
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user