如何在 Roku SG 应用程序中实施深度链接?

How to implement Deep Linking in Roku SG application?

我需要了解深度链接的帮助,因为我们的 Roku Scene Graph 应用程序被 Roku 拒绝了。

Roku 在此处解释了深层链接:https://sdkdocs.roku.com/display/sdkdoc/Deep+Linking,但此文档并未详细说明有关深层链接的所有信息。比如我们如何获取contentId和mediaType?

这是我们在启动时运行的 main() 函数:

function main(args as Dynamic) as Void
    print "args" args
    if (args.ContentId <> invalid) and (args.MediaType <> invalid)
        if (args.mediaType = "season")
            HomeScreen()
        end if 
    end if
end function

应用程序启动后,我们打印 args,得到这个关联数组。但是,这不显示任何 contentId 和 mediaType。

<Component: roAssociativeArray> =
{
    instant_on_run_mode: "foreground"
    lastExitOrTerminationReason: "EXIT_UNKNOWN"
    source: "auto-run-dev"
    splashTime: "1170"
}

使用此 curl 命令,应用程序成功启动并显示 contentId 和 mediaType:

curl -d "" "http://10.1.1.114:8060/launch/dev?contentID=e59066f501310da32b54ec0b64319be0&MediaType=season"

请帮助我们并提供更好的示例来理解和轻松实现深度链接。

深层链接参数由固件传递。如果它们通过,您应该只能处理它们。如果没有传递任何参数,只需显示主屏幕。例如,如果您在 "args" 中有有效的 contentId,您应该找到具有此类 ID 的内容并在频道启动后播放。

你走在正确的轨道上。 Deep Linking 的目的是让用户从 Roku 搜索列表或横幅直接访问您频道的一季或一集。

文档中没有很好的示例说明如何为场景图通道编程,因此我们也必须自己编写。一旦你实现了它,有几种方法可以测试它:

  1. 使用 Eclipse 插件 -> 文件 > 导出 > BrightScript 部署。像这样填写 DeepLinking 参数字段:contentID=1234&MediaType=episode

  2. 使用 Roku Deep Link 测试仪:http://devtools.web.roku.com/DeepLinkingTester/

  3. 将一些深度 link 参数硬编码到您的频道中

以下是我们如何在 main.brs 中实现深度 Linking 逻辑:

sub Main(args as Dynamic)

    screen = createObject("roSGScreen")
    m.port = createObject("roMessagePort")
    screen.setMessagePort(m.port)
    m.global = screen.getGlobalNode()

    'Deep Linking
    'args.ContentId = "78891" 'Testing only
    'args.MediaType = "episode" 'Testing only
    if (args.ContentId <> invalid) and (args.MediaType <> invalid)
        m.global.addField("DeepContentId", "string", true)
        m.global.addField("DeepMediaType", "string", true)

        m.global.DeepContentId = args.ContentId
        m.global.DeepMediaType = args.MediaType
    end if

    scene = screen.createScene("HomeScene")
    screen.show()

    '...load content, other startup logic

    while true
        msg = wait(0, m.port)
        msgType = type(msg)

        if msgType = "roSGScreenEvent"
            if msg.isScreenClosed() then exit while
        end if
    end while

    if screen <> invalid then
        screen.close()
        screen = invalid
    end if
end sub

然后在 HomeScene.brs 的主屏幕上,一旦您的内容已初始化:

'Check for deep link content
if m.global.DeepContentId <> invalid then

    if (m.global.DeepMediaType = "short form" or m.global.DeepMediaType = "movie" or m.global.DeepMediaType = "episode") then
        'find selected content in feed

        'play episode or movie content directly

    else if (m.global.DeepMediaType = "season")
        'find selected content in feed
        'show season screen for content
    else
        ? "Unrecognized Deep Link Media Type"
    end if
    'It may be necessary to remove deep link params
    m.global.DeepContentId = invalid
    m.global.DeepMediaType = invalid
end if

我希望这对您的 Deep Link 和 运行 有所帮助。如果我遗漏了什么,请告诉我。