Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions swiftchan/ViewModels/VLCVideoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyCancellable> = []

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 {
Expand Down
7 changes: 3 additions & 4 deletions swiftchan/Views/Media/VLC/VLCContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading