From 490abaae3bcebc84f3c09934891e7a04458ac68f Mon Sep 17 00:00:00 2001 From: vanities Date: Thu, 12 Jun 2025 17:51:36 -0500 Subject: [PATCH] Fix VLC download progress updates --- swiftchan/ViewModels/VLCVideoViewModel.swift | 10 ++++++++++ swiftchan/Views/Media/VLC/VLCContainerView.swift | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/swiftchan/ViewModels/VLCVideoViewModel.swift b/swiftchan/ViewModels/VLCVideoViewModel.swift index 874871d0..068b3a4a 100644 --- a/swiftchan/ViewModels/VLCVideoViewModel.swift +++ b/swiftchan/ViewModels/VLCVideoViewModel.swift @@ -5,15 +5,25 @@ // Created on 2/1/21. // import SwiftUI +import Combine import MobileVLCKit @MainActor @Observable class VLCVideoViewModel { private(set) var video: VLCVideo + private var cancellables: Set = [] init(url: URL) { video = VLCVideo(url: url) + video.downloadProgress + .publisher(for: \.fractionCompleted) + .receive(on: RunLoop.main) + .sink { [weak self] _ in + guard let self else { return } + self.video = self.video.with(downloadProgress: self.video.downloadProgress) + } + .store(in: &cancellables) } func download() async throws { diff --git a/swiftchan/Views/Media/VLC/VLCContainerView.swift b/swiftchan/Views/Media/VLC/VLCContainerView.swift index 836b9673..8f17f96f 100644 --- a/swiftchan/Views/Media/VLC/VLCContainerView.swift +++ b/swiftchan/Views/Media/VLC/VLCContainerView.swift @@ -37,12 +37,11 @@ struct VLCContainerView: View { if !vlcVideoViewModel.video.downloadProgress.isFinished { VStack { - ProgressView(value: vlcVideoViewModel.video.downloadProgress.fractionCompleted) - .progressViewStyle(.linear) - .padding() - + Text("Downloading") + .foregroundColor(.white) Text("\(Int(vlcVideoViewModel.video.downloadProgress.fractionCompleted * 100))%") .foregroundColor(.white) + .font(.title) } } if vlcVideoViewModel.video.downloadProgress.isFinished && vlcVideoViewModel.video.mediaState == .buffering {