mirror of
https://github.com/yattee/yattee.git
synced 2025-01-07 13:27:08 +00:00
Minor performance improvement
This commit is contained in:
parent
c3e2e5c258
commit
b5f8a0fba2
Model/Player
@ -489,6 +489,18 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
if let currentTime = self.currentTime {
|
if let currentTime = self.currentTime {
|
||||||
self.model.handleSegments(at: currentTime)
|
self.model.handleSegments(at: currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(macOS)
|
||||||
|
guard UIApplication.shared.applicationState != .background else {
|
||||||
|
print("not performing controls updates in background")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if self.controlsUpdates {
|
||||||
|
self.playerTime.duration = self.playerItemDuration ?? .zero
|
||||||
|
self.playerTime.currentTime = self.currentTime ?? .zero
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,6 +342,13 @@ final class MPVBackend: PlayerBackend {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(macOS)
|
||||||
|
guard UIApplication.shared.applicationState != .background else {
|
||||||
|
self.logger.info("not performing controls updates in background")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
self.playerTime.currentTime = self.currentTime ?? .zero
|
self.playerTime.currentTime = self.currentTime ?? .zero
|
||||||
self.playerTime.duration = self.playerItemDuration ?? .zero
|
self.playerTime.duration = self.playerItemDuration ?? .zero
|
||||||
}
|
}
|
||||||
|
@ -789,36 +789,38 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateNowPlayingInfo() {
|
func updateNowPlayingInfo() {
|
||||||
guard let video = currentItem?.video else {
|
#if !os(tvOS)
|
||||||
MPNowPlayingInfoCenter.default().nowPlayingInfo = .none
|
guard let video = currentItem?.video else {
|
||||||
return
|
MPNowPlayingInfoCenter.default().nowPlayingInfo = .none
|
||||||
}
|
return
|
||||||
|
|
||||||
let currentTime = (backend.currentTime?.seconds.isFinite ?? false) ? backend.currentTime!.seconds : 0
|
|
||||||
var nowPlayingInfo: [String: AnyObject] = [
|
|
||||||
MPMediaItemPropertyTitle: video.title as AnyObject,
|
|
||||||
MPMediaItemPropertyArtist: video.author as AnyObject,
|
|
||||||
MPNowPlayingInfoPropertyIsLiveStream: live as AnyObject,
|
|
||||||
MPNowPlayingInfoPropertyElapsedPlaybackTime: currentTime as AnyObject,
|
|
||||||
MPNowPlayingInfoPropertyPlaybackQueueCount: queue.count as AnyObject,
|
|
||||||
MPNowPlayingInfoPropertyPlaybackQueueIndex: 1 as AnyObject,
|
|
||||||
MPMediaItemPropertyMediaType: MPMediaType.anyVideo.rawValue as AnyObject
|
|
||||||
]
|
|
||||||
|
|
||||||
if !currentArtwork.isNil {
|
|
||||||
nowPlayingInfo[MPMediaItemPropertyArtwork] = currentArtwork as AnyObject
|
|
||||||
}
|
|
||||||
|
|
||||||
if !video.live {
|
|
||||||
let itemDuration = (backend.playerItemDuration ?? .zero).seconds
|
|
||||||
let duration = itemDuration.isFinite ? Double(itemDuration) : nil
|
|
||||||
|
|
||||||
if !duration.isNil {
|
|
||||||
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration as AnyObject
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
|
let currentTime = (backend.currentTime?.seconds.isFinite ?? false) ? backend.currentTime!.seconds : 0
|
||||||
|
var nowPlayingInfo: [String: AnyObject] = [
|
||||||
|
MPMediaItemPropertyTitle: video.title as AnyObject,
|
||||||
|
MPMediaItemPropertyArtist: video.author as AnyObject,
|
||||||
|
MPNowPlayingInfoPropertyIsLiveStream: live as AnyObject,
|
||||||
|
MPNowPlayingInfoPropertyElapsedPlaybackTime: currentTime as AnyObject,
|
||||||
|
MPNowPlayingInfoPropertyPlaybackQueueCount: queue.count as AnyObject,
|
||||||
|
MPNowPlayingInfoPropertyPlaybackQueueIndex: 1 as AnyObject,
|
||||||
|
MPMediaItemPropertyMediaType: MPMediaType.anyVideo.rawValue as AnyObject
|
||||||
|
]
|
||||||
|
|
||||||
|
if !currentArtwork.isNil {
|
||||||
|
nowPlayingInfo[MPMediaItemPropertyArtwork] = currentArtwork as AnyObject
|
||||||
|
}
|
||||||
|
|
||||||
|
if !video.live {
|
||||||
|
let itemDuration = (backend.playerItemDuration ?? .zero).seconds
|
||||||
|
let duration = itemDuration.isFinite ? Double(itemDuration) : nil
|
||||||
|
|
||||||
|
if !duration.isNil {
|
||||||
|
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration as AnyObject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCurrentArtwork() {
|
func updateCurrentArtwork() {
|
||||||
|
Loading…
Reference in New Issue
Block a user