clean up force unwrapped runTimeTicks
This commit is contained in:
parent
bcc81213ad
commit
074be8ec37
|
@ -140,7 +140,8 @@ final class VideoPlayerViewModel: ViewModel {
|
||||||
// MARK: Current Time
|
// MARK: Current Time
|
||||||
|
|
||||||
var currentSeconds: Double {
|
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)
|
return round(sliderPercentage * videoDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +257,8 @@ final class VideoPlayerViewModel: ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sliderPercentageChanged(newValue: Double) {
|
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
|
let secondsScrubbedRemaining = videoDuration - currentSeconds
|
||||||
|
|
||||||
leftLabelText = calculateTimeText(from: currentSeconds)
|
leftLabelText = calculateTimeText(from: currentSeconds)
|
||||||
|
|
|
@ -450,7 +450,8 @@ extension VLCPlayerViewController {
|
||||||
|
|
||||||
if startPercentage > 0 {
|
if startPercentage > 0 {
|
||||||
if viewModel.resumeOffset {
|
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)
|
var startSeconds = round((startPercentage / 100) * videoDurationSeconds)
|
||||||
startSeconds = startSeconds.subtract(5, floor: 0)
|
startSeconds = startSeconds.subtract(5, floor: 0)
|
||||||
let newStartPercentage = startSeconds / videoDurationSeconds
|
let newStartPercentage = startSeconds / videoDurationSeconds
|
||||||
|
@ -522,7 +523,8 @@ extension VLCPlayerViewController {
|
||||||
// Necessary math as VLCMediaPlayer doesn't work well
|
// Necessary math as VLCMediaPlayer doesn't work well
|
||||||
// by just setting the position
|
// by just setting the position
|
||||||
let videoPosition = Double(vlcMediaPlayer.time.intValue / 1000)
|
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 secondsScrubbedTo = round(viewModel.sliderPercentage * videoDuration)
|
||||||
let newPositionOffset = secondsScrubbedTo - videoPosition
|
let newPositionOffset = secondsScrubbedTo - videoPosition
|
||||||
|
|
||||||
|
|
|
@ -410,7 +410,8 @@ extension VLCPlayerViewController {
|
||||||
|
|
||||||
if startPercentage > 0 {
|
if startPercentage > 0 {
|
||||||
if viewModel.resumeOffset {
|
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)
|
var startSeconds = round((startPercentage / 100) * videoDurationSeconds)
|
||||||
startSeconds = startSeconds.subtract(5, floor: 0)
|
startSeconds = startSeconds.subtract(5, floor: 0)
|
||||||
let newStartPercentage = startSeconds / videoDurationSeconds
|
let newStartPercentage = startSeconds / videoDurationSeconds
|
||||||
|
@ -490,8 +491,9 @@ extension VLCPlayerViewController {
|
||||||
func setMediaPlayerTimeAtCurrentSlider() {
|
func setMediaPlayerTimeAtCurrentSlider() {
|
||||||
// Necessary math as VLCMediaPlayer doesn't work well
|
// Necessary math as VLCMediaPlayer doesn't work well
|
||||||
// by just setting the position
|
// by just setting the position
|
||||||
|
let runTimeTicks = item.runTimeTicks ?? 0
|
||||||
let videoPosition = Double(vlcMediaPlayer.time.intValue / 1000)
|
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 secondsScrubbedTo = round(viewModel.sliderPercentage * videoDuration)
|
||||||
let newPositionOffset = secondsScrubbedTo - videoPosition
|
let newPositionOffset = secondsScrubbedTo - videoPosition
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue