Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: video crashes #520

Merged
merged 1 commit into from
Sep 30, 2024
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
2 changes: 1 addition & 1 deletion Course/Course/Data/CourseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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 @@ -193,9 +193,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
Loading