Fix duration formatting (#91)
* Fix duration formatting * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
a675811488
commit
bdaaf17785
5 files changed
+48
-9
No files matched your search
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
|
||||
- A crash where the saved auth token is not in a valid format
|
||||
- Video duration formatting for long videos
|
||||
|
||||
## [0.10.0] - 2023-06-25
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ function OnContentSet() as void
|
||||
else
|
||||
m.top.FindNode("liveRect").visible = false
|
||||
if content.lengthSeconds <> invalid and content.lengthSeconds <> 0
|
||||
m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.lengthSeconds)
|
||||
SetDurationText(TimeUtils.GetFormattedTime(content.lengthSeconds))
|
||||
m.top.FindNode("durationRect").visible = true
|
||||
else
|
||||
m.top.FindNode("durationRect").visible = false
|
||||
@@ -42,6 +42,18 @@ function OnContentSet() as void
|
||||
|
||||
end function
|
||||
|
||||
function SetDurationText(text as string)
|
||||
label = m.top.FindNode("durationLabel")
|
||||
rect = m.top.FindNode("durationRect")
|
||||
rectParent = rect.getParent()
|
||||
|
||||
label.text = text
|
||||
size = label.localBoundingRect()
|
||||
|
||||
rect.width = size.width + 16
|
||||
rect.translation = [rectParent.width - rect.width, 162]
|
||||
end function
|
||||
|
||||
function OnThumbnailLoadFailed() as void
|
||||
if m.thumbnail.loadStatus <> "failed"
|
||||
return
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
<Rectangle
|
||||
id="durationRect"
|
||||
width="60"
|
||||
height="25"
|
||||
height="26"
|
||||
color="0x000000"
|
||||
opacity="0.8"
|
||||
translation="[290, 162]"
|
||||
>
|
||||
<Label
|
||||
width="60"
|
||||
height="25"
|
||||
height="26"
|
||||
id="durationLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestSystemFont"
|
||||
translation="[8, 0]"
|
||||
/>
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
namespace TimeUtils
|
||||
' Helper function convert seconds to mm:ss format
|
||||
' Helper function convert seconds to [hh:]mm:ss format
|
||||
' getTime(138) returns 2:18
|
||||
function GetFormattedTime(length as integer) as string
|
||||
minutes = (length \ 60).ToStr()
|
||||
hours = length \ 3600
|
||||
minutes = (length \ 60) mod 60
|
||||
seconds = length mod 60
|
||||
|
||||
if seconds < 10
|
||||
seconds = "0" + seconds.ToStr()
|
||||
else
|
||||
seconds = seconds.ToStr()
|
||||
end if
|
||||
return minutes + ":" + seconds
|
||||
|
||||
if minutes < 10 and hours > 0
|
||||
minutes = "0" + minutes.ToStr()
|
||||
else
|
||||
minutes = minutes.ToStr()
|
||||
end if
|
||||
|
||||
formattedTime = minutes + ":" + seconds
|
||||
|
||||
if hours > 0
|
||||
formattedTime = hours.ToStr() + ":" + formattedTime
|
||||
end if
|
||||
|
||||
return formattedTime
|
||||
end function
|
||||
|
||||
function GetFormattedTimeLeft(unixTimestamp as integer) as string
|
||||
|
||||
@@ -151,10 +151,21 @@
|
||||
}
|
||||
|
||||
function getFormattedTime(length) {
|
||||
const minutes = Math.floor(length / 60).toString();
|
||||
const hours = Math.floor(length / 3600);
|
||||
const minutes = Math.floor((length / 60) % 60);
|
||||
const seconds = length % 60;
|
||||
|
||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||
return minutes + ":" + secondsString;
|
||||
const minutesString =
|
||||
minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
|
||||
|
||||
let formattedTime = minutesString + ":" + secondsString;
|
||||
|
||||
if (hours > 0) {
|
||||
formattedTime = hours.toString() + ":" + formattedTime;
|
||||
}
|
||||
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
function isVideoLive() {
|
||||
|
||||
Reference in new issue
Block a user