From d5a55fac59d771eb6d07576eae5a995cf2b3aad3 Mon Sep 17 00:00:00 2001 From: Anton Yarmolenko Date: Mon, 30 Sep 2024 10:21:03 +0200 Subject: [PATCH] fix: video crashes (#70) (#520) Co-authored-by: Saeed Bashir --- Course/Course/Data/CourseRepository.swift | 2 +- Course/Course/Domain/CourseInteractor.swift | 10 ++++++++-- .../Presentation/Video/PlayerTrackerProtocol.swift | 8 +++++++- .../Presentation/Video/VideoPlayerViewModel.swift | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Course/Course/Data/CourseRepository.swift b/Course/Course/Data/CourseRepository.swift index c068f4722..5da361928 100644 --- a/Course/Course/Data/CourseRepository.swift +++ b/Course/Course/Data/CourseRepository.swift @@ -256,7 +256,7 @@ public class CourseRepository: CourseRepositoryProtocol { } private func parseVideo(encodedVideo: DataLayer.EncodedVideoData?) -> CourseBlockVideo? { - guard let encodedVideo else { + guard let encodedVideo, encodedVideo.url?.isEmpty == false else { return nil } return .init( diff --git a/Course/Course/Domain/CourseInteractor.swift b/Course/Course/Domain/CourseInteractor.swift index e4498d024..42f6074f4 100644 --- a/Course/Course/Domain/CourseInteractor.swift +++ b/Course/Course/Domain/CourseInteractor.swift @@ -216,9 +216,15 @@ public class CourseInteractor: CourseInteractorProtocol { let endTime = startAndEndTimes.last ?? "00:00:00,000" let text = lines[2.. endTimeInverval { + endTimeInverval = startTimeInterval + } + let subtitle = Subtitle(id: id, - fromTo: DateInterval(start: Date(subtitleTime: startTime), - end: Date(subtitleTime: endTime)), + fromTo: DateInterval(start: startTimeInterval, + end: endTimeInverval), text: text.decodedHTMLEntities()) subtitles.append(subtitle) } diff --git a/Course/Course/Presentation/Video/PlayerTrackerProtocol.swift b/Course/Course/Presentation/Video/PlayerTrackerProtocol.swift index 4487bab29..775f8e0d6 100644 --- a/Course/Course/Presentation/Video/PlayerTrackerProtocol.swift +++ b/Course/Course/Presentation/Video/PlayerTrackerProtocol.swift @@ -111,7 +111,13 @@ public class PlayerTracker: PlayerTrackerProtocol { item = AVPlayerItem(url: url) } self.player = AVPlayer(playerItem: item) - timePublisher = CurrentValueSubject(player?.currentTime().seconds ?? 0) + + var playerTime = player?.currentTime().seconds ?? 0.0 + if playerTime.isNaN == true { + playerTime = 0.0 + } + + timePublisher = CurrentValueSubject(playerTime) ratePublisher = CurrentValueSubject(player?.rate ?? 0) finishPublisher = PassthroughSubject() readyPublisher = PassthroughSubject() diff --git a/Course/Course/Presentation/Video/VideoPlayerViewModel.swift b/Course/Course/Presentation/Video/VideoPlayerViewModel.swift index 8e95a31f0..5014596da 100644 --- a/Course/Course/Presentation/Video/VideoPlayerViewModel.swift +++ b/Course/Course/Presentation/Video/VideoPlayerViewModel.swift @@ -103,7 +103,7 @@ public class VideoPlayerViewModel: ObservableObject { subtitles = result } catch { - print(">>>>> ⛔️⛔️⛔️⛔️⛔️⛔️⛔️⛔️", error) + debugLog(">>>>> ⛔️⛔️⛔️⛔️⛔️⛔️⛔️⛔️", error) } }