Skip to content

Commit

Permalink
fix: video crashes (#70) (#520)
Browse files Browse the repository at this point in the history
Co-authored-by: Saeed Bashir <[email protected]>
  • Loading branch information
rnr and saeedbashir authored Sep 30, 2024
1 parent 8dbdcb2 commit d5a55fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Course/Course/Data/CourseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions Course/Course/Domain/CourseInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,15 @@ public class CourseInteractor: CourseInteractorProtocol {
let endTime = startAndEndTimes.last ?? "00:00:00,000"
let text = lines[2..<lines.count].joined(separator: "\n")

let startTimeInterval = Date(subtitleTime: startTime)
var endTimeInverval = Date(subtitleTime: endTime)
if startTimeInterval > 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)
}
Expand Down
8 changes: 7 additions & 1 deletion Course/Course/Presentation/Video/PlayerTrackerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void, Never>()
readyPublisher = PassthroughSubject<Bool, Never>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class VideoPlayerViewModel: ObservableObject {

subtitles = result
} catch {
print(">>>>> ⛔️⛔️⛔️⛔️⛔️⛔️⛔️⛔️", error)
debugLog(">>>>> ⛔️⛔️⛔️⛔️⛔️⛔️⛔️⛔️", error)
}
}

Expand Down

0 comments on commit d5a55fa

Please sign in to comment.