Use Roku's built-in keypress time tracker

This commit is contained in:
1hitsong 2022-06-03 08:15:25 -04:00
parent 0564038158
commit 6ba1fe3c8b

View File

@ -17,6 +17,8 @@ sub init()
m.LoadScreenSaverTimeoutTask.observeField("content", "onScreensaverTimeoutLoaded") m.LoadScreenSaverTimeoutTask.observeField("content", "onScreensaverTimeoutLoaded")
m.LoadScreenSaverTimeoutTask.control = "RUN" m.LoadScreenSaverTimeoutTask.control = "RUN"
m.di = CreateObject("roDeviceInfo")
' Write screen tracker for screensaver ' Write screen tracker for screensaver
WriteAsciiFile("tmp:/scene.temp", "nowplaying") WriteAsciiFile("tmp:/scene.temp", "nowplaying")
MoveFile("tmp:/scene.temp", "tmp:/scene") MoveFile("tmp:/scene.temp", "tmp:/scene")
@ -43,8 +45,6 @@ sub setupScreenSaver()
m.PosterOne.uri = "pkg:/images/logo.png" m.PosterOne.uri = "pkg:/images/logo.png"
m.BounceAnimation = m.top.findNode("BounceAnimation") m.BounceAnimation = m.top.findNode("BounceAnimation")
m.PosterOneFadeIn = m.top.findNode("PosterOneFadeIn") m.PosterOneFadeIn = m.top.findNode("PosterOneFadeIn")
m.screenSaverCounter = 1
end sub end sub
sub setupAnimationTasks() sub setupAnimationTasks()
@ -149,11 +149,9 @@ sub audioPositionChanged()
m.playPositionAnimationWidth.keyValue = [m.playPosition.width, playPositionBarWidth] m.playPositionAnimationWidth.keyValue = [m.playPosition.width, playPositionBarWidth]
m.playPositionAnimation.control = "start" m.playPositionAnimation.control = "start"
m.screenSaverCounter = m.screenSaverCounter + (m.top.audio.position - m.previousAudioPosition)
' Only fall into screensaver logic if the user has screensaver enabled in Roku settings ' Only fall into screensaver logic if the user has screensaver enabled in Roku settings
if m.screenSaverTimeout > 0 if m.screenSaverTimeout > 0
if m.screenSaverCounter >= m.screenSaverTimeout - 2 if m.di.TimeSinceLastKeypress() >= m.screenSaverTimeout - 2
if not screenSaverActive() if not screenSaverActive()
startScreenSaver() startScreenSaver()
end if end if
@ -188,7 +186,6 @@ sub endScreenSaver()
m.screenSaverAlbumCover.opacity = "0" m.screenSaverAlbumCover.opacity = "0"
m.PosterOne.opacity = "0" m.PosterOne.opacity = "0"
m.top.overhangVisible = true m.top.overhangVisible = true
m.screenSaverCounter = 1
m.screenSaverAlbumAnimation.control = "pause" m.screenSaverAlbumAnimation.control = "pause"
m.BounceAnimation.control = "pause" m.BounceAnimation.control = "pause"
end sub end sub
@ -355,9 +352,6 @@ function onKeyEvent(key as string, press as boolean) as boolean
return true return true
end if end if
' Any key press resets the screensaver counter
m.screenSaverCounter = 0
if key = "play" if key = "play"
return playAction() return playAction()
else if key = "back" else if key = "back"