mirror of
https://github.com/dirtydishes/dreamio.git
synced 2026-06-06 13:37:24 +00:00
Start buffering before caption loading
This commit is contained in:
parent
62366c0e25
commit
baec60829d
4 changed files with 166 additions and 6 deletions
|
|
@ -258,13 +258,24 @@ final class NativePlayerViewController: UIViewController {
|
|||
}
|
||||
|
||||
private func resolveSubtitleCandidates(_ candidates: [SubtitleCandidate]) async -> [SubtitleCandidate] {
|
||||
var resolved: [SubtitleCandidate] = []
|
||||
for candidate in candidates {
|
||||
if let playableCandidate = await subtitleResolver.resolve(candidate) {
|
||||
resolved.append(playableCandidate)
|
||||
await withTaskGroup(of: (Int, SubtitleCandidate?).self) { group in
|
||||
for (index, candidate) in candidates.enumerated() {
|
||||
group.addTask { [subtitleResolver] in
|
||||
(index, await subtitleResolver.resolve(candidate))
|
||||
}
|
||||
}
|
||||
|
||||
var resolvedCandidates: [(index: Int, candidate: SubtitleCandidate)] = []
|
||||
for await (index, candidate) in group {
|
||||
if let candidate {
|
||||
resolvedCandidates.append((index, candidate))
|
||||
}
|
||||
}
|
||||
|
||||
return resolvedCandidates
|
||||
.sorted { $0.index < $1.index }
|
||||
.map(\.candidate)
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
private func configureBackend() {
|
||||
|
|
@ -309,10 +320,17 @@ final class NativePlayerViewController: UIViewController {
|
|||
failureContainer.isHidden = true
|
||||
startStartupTimer()
|
||||
backend.play(request: request)
|
||||
addSubtitleCandidates(request.subtitleCandidates)
|
||||
startCaptionLoadingInBackground()
|
||||
revealControls()
|
||||
}
|
||||
|
||||
private func startCaptionLoadingInBackground() {
|
||||
let queuedCount = addSubtitleCandidates(request.subtitleCandidates)
|
||||
#if DEBUG
|
||||
print("[DreamioNativePlayer] startup captions queued=\(queuedCount) total=\(request.subtitleCandidates.count) playbackAlreadyRequested=true")
|
||||
#endif
|
||||
}
|
||||
|
||||
private func startStartupTimer() {
|
||||
startupTimer?.invalidate()
|
||||
startupTimer = Timer.scheduledTimer(withTimeInterval: 20, repeats: false) { [weak self] _ in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue