Open videos via URL scheme

This commit is contained in:
Arkadiusz Fal
2021-10-24 11:16:04 +02:00
parent 8e0af22b94
commit 60c7027429
18 changed files with 230 additions and 189 deletions

View File

@@ -27,17 +27,20 @@ extension PlayerModel {
}
}
func playNow(_ video: Video) {
func playNow(_ video: Video, at time: TimeInterval? = nil) {
addCurrentItemToHistory()
enqueueVideo(video, prepending: true) { _, item in
self.advanceToItem(item)
self.advanceToItem(item, at: time)
}
}
func playItem(_ item: PlayerQueueItem, video: Video? = nil) {
func playItem(_ item: PlayerQueueItem, video: Video? = nil, at time: TimeInterval? = nil) {
currentItem = item
if currentItem.playbackTime.isNil {
if !time.isNil {
currentItem.playbackTime = CMTime(seconds: time!, preferredTimescale: 1_000_000)
} else if currentItem.playbackTime.isNil {
currentItem.playbackTime = .zero
}
@@ -45,7 +48,7 @@ extension PlayerModel {
currentItem.video = video!
}
playVideo(currentVideo!, time: item.playbackTime)
playVideo(currentVideo!, time: currentItem.playbackTime)
}
func advanceToNextItem() {
@@ -56,12 +59,12 @@ extension PlayerModel {
}
}
func advanceToItem(_ newItem: PlayerQueueItem) {
func advanceToItem(_ newItem: PlayerQueueItem, at time: TimeInterval? = nil) {
addCurrentItemToHistory()
let item = remove(newItem)!
loadDetails(newItem.video) { video in
self.playItem(item, video: video)
self.playItem(item, video: video, at: time)
}
}

View File

@@ -32,14 +32,16 @@ extension PlayerModel {
private func skip(_ segment: Segment, at time: CMTime) {
guard segment.endTime.seconds <= playerItemDuration?.seconds ?? .infinity else {
logger.error("item time is: \(time.seconds) and trying to skip to \(playerItemDuration?.seconds ?? .infinity)")
logger.error(
"segment end time is: \(segment.end) when player item duration is: \(playerItemDuration?.seconds ?? .infinity)"
)
return
}
player.seek(to: segment.endTime)
lastSkipped = segment
segmentRestorationTime = time
logger.info("SponsorBlock skipping to: \(segment.endTime)")
logger.info("SponsorBlock skipping to: \(segment.end)")
}
private func shouldSkip(_ segment: Segment, at time: CMTime) -> Bool {