clean up force unwrapped runTimeTicks

This commit is contained in:
jhays 2022-01-13 14:43:27 -06:00
parent bcc81213ad
commit 074be8ec37
3 changed files with 12 additions and 6 deletions

View File

@ -140,7 +140,8 @@ final class VideoPlayerViewModel: ViewModel {
// MARK: Current Time
var currentSeconds: Double {
let videoDuration = Double(item.runTimeTicks! / 10_000_000)
let runTimeTicks = item.runTimeTicks ?? 0
let videoDuration = Double(runTimeTicks / 10_000_000)
return round(sliderPercentage * videoDuration)
}
@ -256,7 +257,8 @@ final class VideoPlayerViewModel: ViewModel {
}
private func sliderPercentageChanged(newValue: Double) {
let videoDuration = Double(item.runTimeTicks! / 10_000_000)
let runTimeTicks = item.runTimeTicks ?? 0
let videoDuration = Double(runTimeTicks / 10_000_000)
let secondsScrubbedRemaining = videoDuration - currentSeconds
leftLabelText = calculateTimeText(from: currentSeconds)

View File

@ -450,7 +450,8 @@ extension VLCPlayerViewController {
if startPercentage > 0 {
if viewModel.resumeOffset {
let videoDurationSeconds = Double(viewModel.item.runTimeTicks! / 10_000_000)
let runTimeTicks = viewModel.item.runTimeTicks ?? 0
let videoDurationSeconds = Double(runTimeTicks / 10_000_000)
var startSeconds = round((startPercentage / 100) * videoDurationSeconds)
startSeconds = startSeconds.subtract(5, floor: 0)
let newStartPercentage = startSeconds / videoDurationSeconds
@ -522,7 +523,8 @@ extension VLCPlayerViewController {
// Necessary math as VLCMediaPlayer doesn't work well
// by just setting the position
let videoPosition = Double(vlcMediaPlayer.time.intValue / 1000)
let videoDuration = Double(viewModel.item.runTimeTicks! / 10_000_000)
let runTimeTicks = viewModel.item.runTimeTicks ?? 0
let videoDuration = Double(runTimeTicks / 10_000_000)
let secondsScrubbedTo = round(viewModel.sliderPercentage * videoDuration)
let newPositionOffset = secondsScrubbedTo - videoPosition

View File

@ -410,7 +410,8 @@ extension VLCPlayerViewController {
if startPercentage > 0 {
if viewModel.resumeOffset {
let videoDurationSeconds = Double(viewModel.item.runTimeTicks! / 10_000_000)
let runTimeTicks = item.runTimeTicks ?? 0
let videoDurationSeconds = Double(runTimeTicks / 10_000_000)
var startSeconds = round((startPercentage / 100) * videoDurationSeconds)
startSeconds = startSeconds.subtract(5, floor: 0)
let newStartPercentage = startSeconds / videoDurationSeconds
@ -490,8 +491,9 @@ extension VLCPlayerViewController {
func setMediaPlayerTimeAtCurrentSlider() {
// Necessary math as VLCMediaPlayer doesn't work well
// by just setting the position
let runTimeTicks = item.runTimeTicks ?? 0
let videoPosition = Double(vlcMediaPlayer.time.intValue / 1000)
let videoDuration = Double(viewModel.item.runTimeTicks! / 10_000_000)
let videoDuration = Double(runTimeTicks / 10_000_000)
let secondsScrubbedTo = round(viewModel.sliderPercentage * videoDuration)
let newPositionOffset = secondsScrubbedTo - videoPosition