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
|
### Fixed
|
||||||
|
|
||||||
- A crash where the saved auth token is not in a valid format
|
- 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
|
## [0.10.0] - 2023-06-25
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function OnContentSet() as void
|
|||||||
else
|
else
|
||||||
m.top.FindNode("liveRect").visible = false
|
m.top.FindNode("liveRect").visible = false
|
||||||
if content.lengthSeconds <> invalid and content.lengthSeconds <> 0
|
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
|
m.top.FindNode("durationRect").visible = true
|
||||||
else
|
else
|
||||||
m.top.FindNode("durationRect").visible = false
|
m.top.FindNode("durationRect").visible = false
|
||||||
@@ -42,6 +42,18 @@ function OnContentSet() as void
|
|||||||
|
|
||||||
end function
|
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
|
function OnThumbnailLoadFailed() as void
|
||||||
if m.thumbnail.loadStatus <> "failed"
|
if m.thumbnail.loadStatus <> "failed"
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -17,18 +17,18 @@
|
|||||||
<Rectangle
|
<Rectangle
|
||||||
id="durationRect"
|
id="durationRect"
|
||||||
width="60"
|
width="60"
|
||||||
height="25"
|
height="26"
|
||||||
color="0x000000"
|
color="0x000000"
|
||||||
opacity="0.8"
|
opacity="0.8"
|
||||||
translation="[290, 162]"
|
translation="[290, 162]"
|
||||||
>
|
>
|
||||||
<Label
|
<Label
|
||||||
width="60"
|
height="26"
|
||||||
height="25"
|
|
||||||
id="durationLabel"
|
id="durationLabel"
|
||||||
horizAlign="center"
|
horizAlign="center"
|
||||||
vertAlign="center"
|
vertAlign="center"
|
||||||
font="font:SmallestSystemFont"
|
font="font:SmallestSystemFont"
|
||||||
|
translation="[8, 0]"
|
||||||
/>
|
/>
|
||||||
</Rectangle>
|
</Rectangle>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
namespace TimeUtils
|
namespace TimeUtils
|
||||||
' Helper function convert seconds to mm:ss format
|
' Helper function convert seconds to [hh:]mm:ss format
|
||||||
' getTime(138) returns 2:18
|
' getTime(138) returns 2:18
|
||||||
function GetFormattedTime(length as integer) as string
|
function GetFormattedTime(length as integer) as string
|
||||||
minutes = (length \ 60).ToStr()
|
hours = length \ 3600
|
||||||
|
minutes = (length \ 60) mod 60
|
||||||
seconds = length mod 60
|
seconds = length mod 60
|
||||||
|
|
||||||
if seconds < 10
|
if seconds < 10
|
||||||
seconds = "0" + seconds.ToStr()
|
seconds = "0" + seconds.ToStr()
|
||||||
else
|
else
|
||||||
seconds = seconds.ToStr()
|
seconds = seconds.ToStr()
|
||||||
end if
|
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
|
end function
|
||||||
|
|
||||||
function GetFormattedTimeLeft(unixTimestamp as integer) as string
|
function GetFormattedTimeLeft(unixTimestamp as integer) as string
|
||||||
|
|||||||
@@ -151,10 +151,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedTime(length) {
|
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 seconds = length % 60;
|
||||||
|
|
||||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
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() {
|
function isVideoLive() {
|
||||||
|
|||||||
Reference in new issue
Block a user