Skip to content

Commit

Permalink
Add leading zero to minutes in pause bar
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Nov 12, 2023
1 parent 8f7b5f8 commit 9de99af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/music/AudioPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub audioPositionChanged()

' Update displayed position timestamp
if isValid(m.global.audioPlayer.position)
m.positionTimestamp.text = secondsToHuman(m.global.audioPlayer.position)
m.positionTimestamp.text = secondsToHuman(m.global.audioPlayer.position, false)
else
m.positionTimestamp.text = "0:00"
end if
Expand Down
4 changes: 2 additions & 2 deletions components/video/PauseMenu.bs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ end sub
' onProgressPercentageChanged: Handler for changes to m.top.progressPercentage param
'
sub onProgressPercentageChanged()
m.videoPositionTime.text = secondsToHuman(m.top.positionTime)
m.videoRemainingTime.text = secondsToHuman(m.top.remainingPositionTime)
m.videoPositionTime.text = secondsToHuman(m.top.positionTime, true)
m.videoRemainingTime.text = secondsToHuman(m.top.remainingPositionTime, true)
m.progressBar.width = m.progressBarBackground.width * m.top.progressPercentage
end sub

Expand Down
29 changes: 22 additions & 7 deletions source/utils/misc.bs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,31 @@ function ticksToHuman(ticks as longinteger) as string
return r
end function

function secondsToHuman(totalSeconds as integer) as string
function secondsToHuman(totalSeconds as integer, addLeadingMinuteZero as boolean) as string
humanTime = ""
hours = stri(int(totalSeconds / 3600)).trim()
minutes = stri(int((totalSeconds - (val(hours) * 3600)) / 60)).trim()
seconds = stri(totalSeconds - (val(hours) * 3600) - (val(minutes) * 60)).trim()
if val(hours) > 0 and val(minutes) < 10 then minutes = "0" + minutes
if val(seconds) < 10 then seconds = "0" + seconds
r = ""
if val(hours) > 0 then r = hours + ":"
r = r + minutes + ":" + seconds
return r

if val(hours) > 0 or addLeadingMinuteZero
if val(minutes) < 10
minutes = "0" + minutes
end if
end if

if val(seconds) < 10
seconds = "0" + seconds
end if

if val(hours) > 0
hours = hours + ":"
else
hours = ""
end if

humanTime = hours + minutes + ":" + seconds

return humanTime
end function

' Format time as 12 or 24 hour format based on system clock setting
Expand Down

0 comments on commit 9de99af

Please sign in to comment.