Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress bar to pause menu #1491

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions components/video/PauseMenu.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ sub init()
m.inactivityTimer = m.top.findNode("inactivityTimer")
m.itemTitle = m.top.findNode("itemTitle")
m.videoPlayPause = m.top.findNode("videoPlayPause")
m.videoPositionTime = m.top.findNode("videoPositionTime")
m.videoRemainingTime = m.top.findNode("videoRemainingTime")
m.progressBar = m.top.findNode("progressBar")
m.progressBarBackground = m.top.findNode("progressBarBackground")

m.top.observeField("visible", "onVisibleChanged")
m.top.observeField("hasFocus", "onFocusChanged")
m.top.observeField("progressPercentage", "onProgressPercentageChanged")
m.top.observeField("playbackState", "onPlaybackStateChanged")
m.top.observeField("itemTitleText", "onItemTitleTextChanged")

Expand All @@ -23,6 +28,14 @@ sub init()
m.deviceInfo = CreateObject("roDeviceInfo")
end sub

' onProgressPercentageChanged: Handler for changes to m.top.progressPercentage param
'
sub onProgressPercentageChanged()
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

' onPlaybackStateChanged: Handler for changes to m.top.playbackState param
'
sub onPlaybackStateChanged()
Expand Down
14 changes: 12 additions & 2 deletions components/video/PauseMenu.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="PauseMenu" extends="Group" initialFocus="chapterNext">
<children>
<Label id="itemTitle" font="font:LargeBoldSystemFont" translation="[103,61]" />
<ScrollingLabel id="itemTitle" font="font:LargeBoldSystemFont" translation="[103,61]" maxWidth="1400" />
<Clock id="clock" translation="[1618, 46]" />

<ButtonGroup id="optionControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="left" translation="[103,120]">
Expand All @@ -10,17 +10,27 @@
<IconButton id="showSubtitleMenu" background="#070707" focusBackground="#00a4dc" padding="0" icon="pkg:/images/icons/subtitle.png" height="65" width="100" />
</ButtonGroup>

<ButtonGroup id="videoControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="center" translation="[960,950]">
<ButtonGroup id="videoControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="center" translation="[960,875]">
<IconButton id="chapterBack" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/previousChapter.png" height="65" width="100" />
<IconButton id="videoPlayPause" background="#070707" focusBackground="#00a4dc" padding="35" icon="pkg:/images/icons/play.png" height="65" width="100" />
<IconButton id="chapterNext" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/nextChapter.png" height="65" width="100" />
</ButtonGroup>

<Rectangle id="progressBarBackground" color="0x00000098" width="1714" height="8" translation="[103,970]">
<Rectangle id="progressBar" color="#e5e4e2FF" width="0" height="8" />
</Rectangle>

<Label id="videoPositionTime" font="font:MediumSystemFont" color="0xffffffFF" translation="[103,985]" />
<Label id="videoRemainingTime" font="font:MediumSystemFont" color="0xffffffFF" horizAlign="right" width="200" translation="[1617,985]" />

<Timer id="inactivityTimer" duration="1" repeat="true" />
</children>
<interface>
<field id="itemTitleText" type="string" />
<field id="inactiveTimeout" type="integer" />
<field id="progressPercentage" type="float" />
<field id="positionTime" type="float" />
<field id="remainingPositionTime" type="float" />
<field id="playbackState" type="string" alwaysNotify="true" />
<field id="action" type="string" alwaysNotify="true" />
<field id="showChapterList" type="boolean" alwaysNotify="true" />
Expand Down
10 changes: 8 additions & 2 deletions components/video/VideoPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ end sub

' When Video Player state changes
sub onPositionChanged()

' Pass video position data into pause menu
m.pauseMenu.progressPercentage = m.top.position / m.top.duration
m.pauseMenu.positionTime = m.top.position
m.pauseMenu.remainingPositionTime = m.top.duration - m.top.position

if isValid(m.captionTask)
m.captionTask.currentPos = Int(m.top.position * 1000)
end if
Expand Down Expand Up @@ -612,15 +618,15 @@ function onKeyEvent(key as string, press as boolean) as boolean

if not press then return false

if key = "down"
if key = "down" and not m.top.trickPlayBar.visible
if not m.LoadMetaDataTask.isIntro
m.pauseMenu.visible = true
m.pauseMenu.hasFocus = true
m.pauseMenu.setFocus(true)
return true
end if

else if key = "up"
else if key = "up" and not m.top.trickPlayBar.visible
if not m.LoadMetaDataTask.isIntro
m.pauseMenu.visible = true
m.pauseMenu.hasFocus = true
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