diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55c44f13..800aaa4d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Small improvement in the context menu of the Playlist view
+- Videos can be paused and resumed using the `Ok` remote button
## [0.20.1] - 2024-02-23
diff --git a/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs b/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
index 5a4a9a00..15d533fd 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
@@ -34,6 +34,7 @@ function VideoContentTask(input as object) as object
contentNode.title = metadata.title
contentNode.secondaryTitle = metadata.author
+ contentNode.live = metadata.liveNow
streamUrls = CreateStreamUrls(metadata, service, preferencesNode, playletServerPort)
contentNode.url = streamUrls[0]
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
index 7fecba4e..9339fe83 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
@@ -16,6 +16,8 @@ function Init()
m.fullScreenHintLabel = m.top.findNode("fullScreenHintLabel")
m.fullScreenHintTimer = m.top.findNode("fullScreenHintTimer")
m.fullScreenHintTimer.ObserveField("fire", FuncName(OnFullScreenHintTimer))
+ m.trickplayUITimer = m.top.findNode("trickplayUITimer")
+ m.trickplayUITimer.ObserveField("fire", FuncName(OnTrickplayUITimer))
' videoPlayingSuccess indicates if we started playing a video successfully
' We use it to detect if we should try another link for a video, or if another error
@@ -26,6 +28,13 @@ function Init()
' still trying to find a working stream url
m.ignoreNextFinishedState = false
+ ' Indicates that we're currently paused and seeking position
+ m.isSeekingPosition = false
+
+ ' Checks if current RokuOS version has showUI field in Video node
+ m.showUIEnabled = m.top.hasField("showUI")
+ LogInfo(`Custom OK handler is ${m.showUIEnabled ? "enabled" : "disabled"}`)
+
' asyncStopSemantics available since Roku OS 12.5
' It is set to true because stopping synchronously causes timeout and crash
' Usually we would need to wait for the video state to move to "stopping" then to "stopped"
@@ -170,6 +179,12 @@ function OnVideoPlayerStateChange() as void
state = m.top.state
content = m.top.content
+
+ ' Reset isSeekingPosition when started to play the video
+ if state = "playing"
+ m.isSeekingPosition = false
+ end if
+
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
if state = "playing" and not m.videoPlayingSuccess
@@ -244,6 +259,69 @@ function OnVideoFinished() as void
end if
end function
+function IsLiveVideo() as boolean
+ if m.top.content <> invalid
+ return m.top.content.live
+ end if
+ return false
+end function
+
+function ShowUIAndStartTimer()
+ if m.showUIEnabled
+ m.top.showUI = { "show": true, "trickPlaybar": true, "titleAndTime": true, "trickplayBackgroundOverlay": true, "focusTrickplayBar": false }
+ m.trickplayUITimer.control = "start"
+ end if
+end function
+
+function HideUIAndStopTimer()
+ if m.showUIEnabled
+ m.top.showUI = { "show": false, "focusTrickplayBar": false }
+ m.trickplayUITimer.control = "stop"
+ end if
+end function
+
+function HandleOKPress() as boolean
+ if not m.showUIEnabled
+ return false
+ end if
+
+ handled = false
+ state = m.top.state
+ uiVisible = m.top.trickPlaybar.visible
+ isLive = IsLiveVideo()
+ LogInfo(`Handling OK button: state = ${state}, uiVisible = ${uiVisible} isLive = ${isLive}`)
+ if state = "playing"
+ if not uiVisible
+ ' Video is playing and UI is not visible, show it
+ ShowUIAndStartTimer()
+ else if not isLive
+ ' Trickplay bar is visible and video is currently played, pause it and retain the UI
+ m.trickplayUITimer.control = "stop"
+ m.top.control = "pause"
+ ShowUIAndStartTimer()
+ else
+ HideUIAndStopTimer()
+ end if
+ handled = true
+ else if state = "paused"
+ ' Exit early if we're in seeking mode to avoid messing up internal Video node state
+ if m.isSeekingPosition
+ return false
+ end if
+
+ if not uiVisible
+ ' Video is paused and UI is not visible, show it
+ ShowUIAndStartTimer()
+ else
+ ' Video is currently paused with visible UI, resume it and hide UI
+ HideUIAndStopTimer()
+ m.top.control = "resume"
+ end if
+ handled = true
+ end if
+ return handled
+end function
+
function OnkeyEvent(key as string, press as boolean) as boolean
if press = false
return false
@@ -261,6 +339,19 @@ function OnkeyEvent(key as string, press as boolean) as boolean
m.videoQueue.closePlayer = true
return true
end if
+
+ if key = "OK"
+ return HandleOKPress()
+ end if
+
+ if key = "left" or key = "right" or key = "rewind" or key = "fastforward"
+ ' We're paused and one of the buttons is pressed: left, right ff, rw.
+ ' That means we're seeking position. Check that in HandleOKPress and exit early
+ m.isSeekingPosition = true
+ end if
+
+ ' Always stop UI timer when pressing any button to avoid UI being hidden twice
+ m.trickplayUITimer.control = "stop"
return false
end function
@@ -282,6 +373,8 @@ function SetupAnimation()
end function
function OnFullScreenChange()
+ HideUIAndStopTimer()
+
m.widthInterpolator.reverse = m.container.fullscreen
m.heightInterpolator.reverse = m.container.fullscreen
m.translationInterpolator.reverse = m.container.fullscreen
@@ -313,6 +406,10 @@ function OnShowFullScreenHint() as void
m.fullScreenHintTimer.control = "start"
end function
+function OnTrickplayUITimer()
+ HideUIAndStopTimer()
+end function
+
function OnFullScreenHintTimer()
showFullScreenHint = m.top.showFullScreenHint
m.fullScreenHint.visible = showFullScreenHint
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
index a9a46c31..d76a9ebd 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
@@ -16,53 +16,17 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
\ No newline at end of file