|
@@ -34,10 +34,11 @@ class NCPlayer: NSObject {
|
|
|
private var playerToolBar: NCPlayerToolBar?
|
|
|
|
|
|
public var metadata: tableMetadata?
|
|
|
+ public var player: AVPlayer?
|
|
|
public var videoLayer: AVPlayerLayer?
|
|
|
|
|
|
init(url: URL) {
|
|
|
- appDelegate.player = AVPlayer(url: url)
|
|
|
+ self.player = AVPlayer(url: url)
|
|
|
}
|
|
|
|
|
|
deinit {
|
|
@@ -49,28 +50,28 @@ class NCPlayer: NSObject {
|
|
|
self.playerToolBar = playerToolBar
|
|
|
self.metadata = metadata
|
|
|
|
|
|
- appDelegate.player?.isMuted = CCUtility.getAudioMute()
|
|
|
- appDelegate.player?.seek(to: .zero)
|
|
|
+ self.player?.isMuted = CCUtility.getAudioMute()
|
|
|
+ self.player?.seek(to: .zero)
|
|
|
|
|
|
// At end go back to start & show toolbar
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: appDelegate.player?.currentItem, queue: .main) { (notification) in
|
|
|
- if let item = notification.object as? AVPlayerItem, let currentItem = self.appDelegate.player?.currentItem, item == currentItem {
|
|
|
- self.appDelegate.player?.seek(to: .zero)
|
|
|
+ NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: self.player?.currentItem, queue: .main) { (notification) in
|
|
|
+ if let item = notification.object as? AVPlayerItem, let currentItem = self.player?.currentItem, item == currentItem {
|
|
|
+ self.player?.seek(to: .zero)
|
|
|
self.playerToolBar?.showToolBar(metadata: metadata, detailView: nil)
|
|
|
NCKTVHTTPCache.shared.saveCache(metadata: metadata)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- appDelegate.player?.currentItem?.asset.loadValuesAsynchronously(forKeys: ["duration", "playable"], completionHandler: {
|
|
|
- if let duration: CMTime = (self.appDelegate.player?.currentItem?.asset.duration) {
|
|
|
+ self.player?.currentItem?.asset.loadValuesAsynchronously(forKeys: ["duration", "playable"], completionHandler: {
|
|
|
+ if let duration: CMTime = (self.player?.currentItem?.asset.duration) {
|
|
|
var error: NSError? = nil
|
|
|
- let status = self.appDelegate.player?.currentItem?.asset.statusOfValue(forKey: "playable", error: &error)
|
|
|
+ let status = self.player?.currentItem?.asset.statusOfValue(forKey: "playable", error: &error)
|
|
|
switch status {
|
|
|
case .loaded:
|
|
|
DispatchQueue.main.async {
|
|
|
if let imageVideoContainer = imageVideoContainer {
|
|
|
self.imageVideoContainer = imageVideoContainer
|
|
|
- self.videoLayer = AVPlayerLayer(player: self.appDelegate.player)
|
|
|
+ self.videoLayer = AVPlayerLayer(player: self.player)
|
|
|
self.videoLayer!.frame = imageVideoContainer.bounds
|
|
|
self.videoLayer!.videoGravity = .resizeAspect
|
|
|
imageVideoContainer.layer.addSublayer(self.videoLayer!)
|
|
@@ -81,7 +82,7 @@ class NCPlayer: NSObject {
|
|
|
NCManageDatabase.shared.addVideoTime(metadata: metadata, time: nil, durationSeconds: self.durationSeconds)
|
|
|
// NO Live Photo, seek to datamebase time
|
|
|
if !metadata.livePhoto, let time = NCManageDatabase.shared.getVideoTime(metadata: metadata) {
|
|
|
- self.appDelegate.player?.seek(to: time)
|
|
|
+ self.player?.seek(to: time)
|
|
|
}
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
|
playerToolBar?.setBarPlayer(ncplayer: self)
|
|
@@ -112,7 +113,7 @@ class NCPlayer: NSObject {
|
|
|
@objc func applicationDidEnterBackground(_ notification: NSNotification) {
|
|
|
|
|
|
if metadata?.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
|
|
|
- appDelegate.player?.pause()
|
|
|
+ self.player?.pause()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -128,24 +129,24 @@ class NCPlayer: NSObject {
|
|
|
|
|
|
func videoPlay() {
|
|
|
|
|
|
- appDelegate.player?.play()
|
|
|
+ self.player?.play()
|
|
|
}
|
|
|
|
|
|
func videoPause() {
|
|
|
|
|
|
- appDelegate.player?.pause()
|
|
|
+ self.player?.pause()
|
|
|
}
|
|
|
|
|
|
func saveCurrentTime() {
|
|
|
guard let metadata = self.metadata else { return }
|
|
|
|
|
|
- NCManageDatabase.shared.addVideoTime(metadata: metadata, time: appDelegate.player?.currentTime(), durationSeconds: nil)
|
|
|
+ NCManageDatabase.shared.addVideoTime(metadata: metadata, time: self.player?.currentTime(), durationSeconds: nil)
|
|
|
}
|
|
|
|
|
|
func videoSeek(time: CMTime) {
|
|
|
guard let metadata = self.metadata else { return }
|
|
|
|
|
|
- appDelegate.player?.seek(to: time)
|
|
|
+ self.player?.seek(to: time)
|
|
|
NCManageDatabase.shared.addVideoTime(metadata: metadata, time: time, durationSeconds: nil)
|
|
|
}
|
|
|
|
|
@@ -158,7 +159,7 @@ class NCPlayer: NSObject {
|
|
|
|
|
|
func getVideoCurrentSeconds() -> Float64 {
|
|
|
|
|
|
- return CMTimeGetSeconds(appDelegate.player?.currentTime() ?? .zero)
|
|
|
+ return CMTimeGetSeconds(self.player?.currentTime() ?? .zero)
|
|
|
}
|
|
|
|
|
|
func getVideoDurationSeconds() -> Float64 {
|
|
@@ -170,7 +171,7 @@ class NCPlayer: NSObject {
|
|
|
|
|
|
var image: UIImage?
|
|
|
|
|
|
- if let asset = appDelegate.player?.currentItem?.asset {
|
|
|
+ if let asset = self.player?.currentItem?.asset {
|
|
|
|
|
|
do {
|
|
|
let imageGenerator = AVAssetImageGenerator(asset: asset)
|