mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 22:30:32 +05:30
Fix #163
This commit is contained in:
parent
31aead553c
commit
4509b6229a
@ -1,4 +1,5 @@
|
|||||||
import CoreMedia
|
import CoreMedia
|
||||||
|
import AVFAudio
|
||||||
import Defaults
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@ -18,23 +19,42 @@ extension PlayerModel {
|
|||||||
var nextSegments = [firstSegment]
|
var nextSegments = [firstSegment]
|
||||||
|
|
||||||
while let segment = sponsorBlock.segments.first(where: {
|
while let segment = sponsorBlock.segments.first(where: {
|
||||||
|
!nextSegments.contains($0) &&
|
||||||
$0.timeInSegment(.secondsInDefaultTimescale(nextSegments.last!.end + 2))
|
$0.timeInSegment(.secondsInDefaultTimescale(nextSegments.last!.end + 2))
|
||||||
}) {
|
}) {
|
||||||
nextSegments.append(segment)
|
nextSegments.append(segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let segmentToSkip = nextSegments.last(where: { $0.endTime <= playerItemDuration ?? .zero }),
|
if let segmentToSkip = nextSegments.last, shouldSkip(segmentToSkip, at: time) {
|
||||||
shouldSkip(segmentToSkip, at: time)
|
|
||||||
{
|
|
||||||
skip(segmentToSkip, at: time)
|
skip(segmentToSkip, at: time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func skip(_ segment: Segment, at time: CMTime) {
|
private func skip(_ segment: Segment, at time: CMTime) {
|
||||||
guard segment.endTime.seconds <= playerItemDuration?.seconds ?? .infinity else {
|
if let duration = playerItemDuration, segment.endTime.seconds >= duration.seconds - 3 {
|
||||||
logger.error(
|
logger.error("segment end time is: \(segment.end) when player item duration is: \(duration.seconds)")
|
||||||
"segment end time is: \(segment.end) when player item duration is: \(playerItemDuration?.seconds ?? .infinity)"
|
|
||||||
)
|
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.prepareCurrentItemForHistory(finished: true)
|
||||||
|
self.pause()
|
||||||
|
|
||||||
|
if self.queue.isEmpty {
|
||||||
|
#if !os(macOS)
|
||||||
|
try? AVAudioSession.sharedInstance().setActive(false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
self.resetQueue()
|
||||||
|
self.hide()
|
||||||
|
} else {
|
||||||
|
self.advanceToNextItem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class Segment: ObservableObject, Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var endTime: CMTime {
|
var endTime: CMTime {
|
||||||
CMTime(seconds: end, preferredTimescale: 1000)
|
.secondsInDefaultTimescale(end)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(category: String, segment: [Double], uuid: String, videoDuration: Int) {
|
init(category: String, segment: [Double], uuid: String, videoDuration: Int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user