Add transport commands
This commit is contained in:
1 parent
4ef84a2f1f
commit
ae1d2b8acf
8 files changed
+197
-1
No files matched your search
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Support for base transport commands (certification)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Error message when account requires age verification
|
||||
|
||||
@@ -70,6 +70,7 @@ function OnLoadStatusChanged() as void
|
||||
m.scene.playletLibLoadedUrl = libUrl
|
||||
container = m.scene.findNode("MainSceneContainer")
|
||||
container.createChild("PlayletLib:MainScene")
|
||||
m.scene.libSceneCreated = true
|
||||
return
|
||||
end if
|
||||
|
||||
@@ -81,6 +82,10 @@ function OnLoadStatusChanged() as void
|
||||
end if
|
||||
end function
|
||||
|
||||
function CreateInputTransportEventsHandler(_unused as dynamic) as object
|
||||
return CreateObject("roSGNode", "PlayletLib:InputTransportEventsHandler")
|
||||
end function
|
||||
|
||||
function RemoveComponentLibrary() as void
|
||||
if m.lib = invalid
|
||||
return
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
<field id="launchArgs" type="assocarray" />
|
||||
<field id="inputArgs" type="assocarray" alwaysNotify="true" />
|
||||
<field id="playletLibLoadedUrl" type="assocarray" />
|
||||
<field id="libSceneCreated" type="bool" />
|
||||
<field id="systemLogEvent" type="assocarray" alwaysNotify="true" />
|
||||
<field id="enableSystemLogType" type="string" />
|
||||
<field id="lastExitInfo" type="assocarray" />
|
||||
<function name="CreateInputTransportEventsHandler" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="pkg:/source/Dialog.bs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/Manifest.bs" />
|
||||
|
||||
@@ -30,6 +30,10 @@ confirm_partner_button=1
|
||||
|
||||
supports_input_launch=1
|
||||
|
||||
supports_voice_roinput=1
|
||||
supports_etc_seek=1
|
||||
supports_etc_next=1
|
||||
|
||||
requires_widevine_drm=1
|
||||
requires_widevine_version=1.0
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ function Main(args as object) as void
|
||||
|
||||
scene = screen.CreateScene("BootstrapScene")
|
||||
screen.show()
|
||||
scene.ObserveField("libSceneCreated", port)
|
||||
|
||||
AppManager.CaptureLastExitInfo(scene)
|
||||
|
||||
@@ -49,6 +50,8 @@ function Main(args as object) as void
|
||||
|
||||
input = CreateObject("roInput")
|
||||
input.setMessagePort(port)
|
||||
input.EnableTransportEvents()
|
||||
transportEventsHandler = invalid
|
||||
|
||||
systemLog = CreateObject("roSystemLog")
|
||||
systemLog.SetMessagePort(port)
|
||||
@@ -83,8 +86,21 @@ function Main(args as object) as void
|
||||
if field = "enableSystemLogType"
|
||||
systemLog.EnableType(data)
|
||||
end if
|
||||
if field = "libSceneCreated"
|
||||
scene.unobserveField("libSceneCreated")
|
||||
transportEventsHandler = scene@.CreateInputTransportEventsHandler()
|
||||
end if
|
||||
else if msgType = "roInputEvent"
|
||||
scene.inputArgs = msg.getInfo()
|
||||
info = msg.getInfo()
|
||||
if info.type = "transport"
|
||||
status = "unhandled"
|
||||
if transportEventsHandler <> invalid
|
||||
status = transportEventsHandler@.HandleTransportEvent(info)
|
||||
end if
|
||||
input.EventResponse({ id: info.id, status: status })
|
||||
else
|
||||
scene.inputArgs = info
|
||||
end if
|
||||
end if
|
||||
end while
|
||||
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "TransportEvents.types.bs"
|
||||
|
||||
function Init()
|
||||
m.appManager = CreateObject("roAppManager")
|
||||
m.videoQueue = m.top.getScene().findNode("VideoQueue")
|
||||
|
||||
' TODO:P2 ok, forward, rewind, replay, next and skip need support in the player or the queue. Until then they
|
||||
' have no entry here, and answer unhandled.
|
||||
m.commandHandlers = {}
|
||||
m.commandHandlers[TransportCommand.Play] = PlayCommand
|
||||
m.commandHandlers[TransportCommand.Pause] = PauseCommand
|
||||
m.commandHandlers[TransportCommand.Stop] = PauseCommand
|
||||
m.commandHandlers[TransportCommand.Seek] = SeekCommand
|
||||
m.commandHandlers[TransportCommand.StartOver] = StartOverCommand
|
||||
m.commandHandlers[TransportCommand.NowPlaying] = NowPlayingCommand
|
||||
m.commandHandlers[TransportCommand.Like] = NotSupportedCommand
|
||||
m.commandHandlers[TransportCommand.Dislike] = NotSupportedCommand
|
||||
m.commandHandlers[TransportCommand.Shuffle] = NotSupportedCommand
|
||||
m.commandHandlers[TransportCommand.Loop] = NotSupportedCommand
|
||||
end function
|
||||
|
||||
function HandleTransportEvent(event as object) as string
|
||||
status = RouteTransportEvent(event)
|
||||
LogInfo("transport event", event, "->", status)
|
||||
return status
|
||||
end function
|
||||
|
||||
function RouteTransportEvent(event as object) as string
|
||||
commandHandler = m.commandHandlers[ValidString(event.command)]
|
||||
if commandHandler = invalid
|
||||
return TransportStatus.Unhandled
|
||||
end if
|
||||
return commandHandler(event)
|
||||
end function
|
||||
|
||||
function PlayCommand(_event as object) as string
|
||||
player = m.videoQueue.player
|
||||
if player = invalid
|
||||
return TransportStatus.Unhandled
|
||||
end if
|
||||
|
||||
if player.state = "paused"
|
||||
m.videoQueue.play = true
|
||||
end if
|
||||
return TransportStatus.Success
|
||||
end function
|
||||
|
||||
function PauseCommand(_event as object) as string
|
||||
player = m.videoQueue.player
|
||||
if player = invalid
|
||||
return TransportStatus.Unhandled
|
||||
end if
|
||||
|
||||
if player.state = "paused"
|
||||
return TransportStatus.ErrorRedundant
|
||||
end if
|
||||
m.videoQueue.pause = true
|
||||
return TransportStatus.Success
|
||||
end function
|
||||
|
||||
function SeekCommand(event as object) as string
|
||||
player = m.videoQueue.player
|
||||
if player = invalid
|
||||
return TransportStatus.Unhandled
|
||||
end if
|
||||
|
||||
deltaSeconds = ValidString(event.duration).ToInt()
|
||||
if deltaSeconds <= 0
|
||||
return TransportStatus.Error
|
||||
end if
|
||||
if event.direction = TransportSeekDirection.Backward
|
||||
deltaSeconds = -deltaSeconds
|
||||
end if
|
||||
|
||||
targetSeconds = player.position + deltaSeconds
|
||||
status = TransportStatus.Success
|
||||
if targetSeconds < 0
|
||||
targetSeconds = 0
|
||||
status = TransportStatus.SuccessSeekStart
|
||||
else if player.duration > 0 and targetSeconds > player.duration
|
||||
targetSeconds = player.duration
|
||||
status = TransportStatus.SuccessSeekEnd
|
||||
end if
|
||||
|
||||
player.setSeek = targetSeconds
|
||||
return status
|
||||
end function
|
||||
|
||||
function StartOverCommand(_event as object) as string
|
||||
player = m.videoQueue.player
|
||||
if player = invalid
|
||||
return TransportStatus.Unhandled
|
||||
end if
|
||||
|
||||
player.setSeek = 0
|
||||
return TransportStatus.Success
|
||||
end function
|
||||
|
||||
function NowPlayingCommand(_event as object) as string
|
||||
player = m.videoQueue.player
|
||||
if player = invalid
|
||||
m.appManager.SetNowPlayingContentMetaData(invalid)
|
||||
return TransportStatus.Success
|
||||
end if
|
||||
|
||||
content = player.content
|
||||
if content = invalid or StringUtils.IsNullOrEmpty(content.title)
|
||||
m.appManager.SetNowPlayingContentMetaData(invalid)
|
||||
return TransportStatus.ErrorGeneric
|
||||
end if
|
||||
|
||||
m.appManager.SetNowPlayingContentMetaData({ title: content.title, contentType: "movie" })
|
||||
return TransportStatus.Success
|
||||
end function
|
||||
|
||||
function NotSupportedCommand(_event as object) as string
|
||||
return TransportStatus.ErrorChannel
|
||||
end function
|
||||
@@ -0,0 +1,5 @@
|
||||
<component name="InputTransportEventsHandler" extends="Node">
|
||||
<interface>
|
||||
<function name="HandleTransportEvent" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,39 @@
|
||||
' https://developer.roku.com/docs/developer/media-playback/voice-controls/transport-controls.md
|
||||
enum TransportCommand
|
||||
Play = "play"
|
||||
Pause = "pause"
|
||||
stop = "stop"
|
||||
Ok = "ok"
|
||||
Forward = "forward"
|
||||
Rewind = "rewind"
|
||||
Replay = "replay"
|
||||
StartOver = "startover"
|
||||
Seek = "seek"
|
||||
next = "next"
|
||||
Skip = "skip"
|
||||
NowPlaying = "nowplaying"
|
||||
Like = "like"
|
||||
Dislike = "dislike"
|
||||
Shuffle = "shuffle"
|
||||
Loop = "loop"
|
||||
end enum
|
||||
|
||||
enum TransportSeekDirection
|
||||
Forward = "forward"
|
||||
Backward = "backward"
|
||||
end enum
|
||||
|
||||
' https://developer.roku.com/docs/references/brightscript/interfaces/ifinput.md#eventresponseroassociativearray-aa-as-boolean
|
||||
enum TransportStatus
|
||||
Success = "success"
|
||||
SuccessSeekStart = "success.seek-start"
|
||||
SuccessSeekEnd = "success.seek-end"
|
||||
Unhandled = "unhandled"
|
||||
Error = "error"
|
||||
ErrorGeneric = "error.generic"
|
||||
ErrorAd = "error.ad"
|
||||
ErrorChannel = "error.channel"
|
||||
ErrorLive = "error.live"
|
||||
ErrorNoMedia = "error.no-media"
|
||||
ErrorRedundant = "error.redundant"
|
||||
end enum
|
||||
Reference in new issue
Block a user