【问题标题】:How to implement deep linking in Roku VideoPlayer Sample channel如何在 Roku VideoPlayer 示例频道中实现深度链接
【发布时间】:2018-06-24 02:07:14
【问题描述】:

我们使用 Roku VideoPlayer Sample Channel (https://github.com/rokudev/videoplayer-channel) 开发了一个 Roku 频道。尽管最近向 Roku 提交的文件因未提供深度链接功能而被拒绝。 main.brs 提供了解析深层链接请求的方法,我已经能够实现该深层链接以基于 curl 命令获取我的 contentIDmediaType,如下所示:

curl -d '' 'http://192.168.1.24:8060/launch/dev?MediaType=special&contentID=49479'

main.brs cmets 说

在此处启动/准备映射到 contentID 的内容。

我们正在使用 xml 文件来提供 Roku“类别”屏幕和从类别屏幕(包括跳板屏幕)选择项目后的列表屏幕。在这些 xml 文件中,我们标记了每个视频项目的 contentIDmediaType

我对 Roku 开发还很陌生。虽然我们之前已经能够使用他们的视频频道模板创建频道,但我不知道如何“启动/准备映射到 contentID 的内容”。我已经搜索并尝试了各种其他调用(即 - playMedia(ContentID, Screen)),但在调试器上出现与“函数调用运算符 () 尝试在非函数上”相关的错误。

我将不胜感激有关如何根据使用深度链接命令传递的contentID 的值跳转到视频跳板的说明。或者一种基于 xml 文件中的contentID 播放视频的方法。

这是我的 main.brs:

sub Main(input as Dynamic)
  print "################"
  print "Start of Channel"
  print "################"
  ' Add deep linking support here. Input is an associative array containing
  ' parameters that the client defines. Examples include "options, contentID, etc."
  ' See guide here: https://sdkdocs.roku.com/display/sdkdoc/External+Control+Guide
  ' For example, if a user clicks on an ad for a movie that your app provides,
  ' you will have mapped that movie to a contentID and you can parse that ID
  ' out from the input parameter here.
  ' Call the service provider API to look up
  ' the content details, or right data from feed for id
  if input <> invalid
    print "Received Input -- write code here to check it!"
    if input.reason <> invalid
      if input.reason = "ad" then
        print "Channel launched from ad click"
        'do ad stuff here
      end if
    end if
    if input.contentID <> invalid
      m.contentID = input.contentID
      print "contentID is: " + input.contentID
      print "mediaType is: " + input.mediaType
      'launch/prep the content mapped to the contentID here

    end if
  end if
  showHeroScreen(input)
end sub

' Initializes the scene and shows the main homepage.
' Handles closing of the channel.
sub showHeroScreen(input as object)
  print "main.brs - [showHeroScreen]"
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("VideoScene")
  m.global = screen.getGlobalNode()
  'Deep link params
  m.global.addFields({ input: input })
  screen.show()

  while(true)
    msg = wait(0, m.port)
    msgType = type(msg)
    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed() then return
    end if
  end while
end sub

我在想是否可以在 screen.show 调用之前正确设置深度链接的参数,它应该可以工作吗?使用 curl 调用深层链接时,我可以使用调试器输出 outputID 和 mediaType 值,但它只是进入主屏幕,而不提示深层链接的视频。

感谢任何帮助。

【问题讨论】:

  • 借助一些额外的外部帮助,我能够建立深层链接。深度链接是通过 UriHandler.brs 处理的,方法是检查结果值,然后调用 UriHandlers.brs 中的单独函数来执行深度链接。

标签: deep-linking roku


【解决方案1】:

请查看我的 GitHub REPO 以获得简单的深度链接示例。

小解释: 首先,我像这样输入我的 main.brs:

sub Main(args as Dynamic) as Void

    showSGScreen(args)
end sub

“args”将由 Roku 固件提供! 在我的 showSGScreen Sub 中,你会发现:

'DeepLinking
if args.contentId <> invalid AND args.mediaType <> invalid
    m.scene.contentDLId = args.contentId
    m.scene.mediaDPType = args.mediaType
    m.scene.deepLinkingLand = true
end if

现在查看我的 audiocontent.xml 文件:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<AudioContent>
  <audio actors = "Artist - Unknown" album ="Album - Unknown" title = "KISS FM - LIVE STREAM" streamformat = "es.aac-adts" url = "http://80.86.106.143:9128/kissfm.aacp" HDPosterUrl = "pkg:/images/radio_stations_img/kiss_fm.png" Rating = "true" TrackIDAudio = "1" ShortDescriptionLine1 = "short-form"/>
  <audio actors = "Artist - Unknown" album ="Album - Unknown" title = "TDI Radio - LIVE STREAM" streamformat = "mp3" url = "http://streaming.tdiradio.com:8000/tdiradiob" HDPosterUrl = "pkg:/images/radio_stations_img/tdi_radio.png" Rating = "true" TrackIDAudio = "2" ShortDescriptionLine1 = "short-form"/>
  <audio actors = "Artist - Unknown" album ="Album - Unknown" title = "Polskie Radio - LIVE STREAM" streamformat = "hls" url = "http://stream85.polskieradio.pl/omniaaxe/k11.stream/playlist.m3u8" HDPosterUrl = "pkg:/images/radio_stations_img/polskie_radio.png" Rating = "true" TrackIDAudio = "3" ShortDescriptionLine1 = "short-form"/>
  <audio actors = "Edgar Allan Yo and Shporky Pork" album ="Mony Pajton EP" title = "Niko kao Ja - MP3" streamformat = "mp3" url = "pkg:/mp3/Edgar_Allan_Yo_and_Shporky_Pork_Niko_Kao_Ja.mp3"    HDPosterUrl = "pkg:/images/mp3_img/mony_pajton.png" Rating = "false" TrackIDAudio = "4" ShortDescriptionLine1 = "short-form"/>
  <audio actors = "Edgar Allan Yo and Shporky Pork" album ="Mony Pajton EP" title = "Zatvaramo Krug - MP3" streamformat = "mp3" url = "pkg:/mp3/Edgar_Allan_Yo_and_Shporky_Pork_Zatvaramo_Krug.mp3" HDPosterUrl = "pkg:/images/mp3_img/mony_pajton.png" Rating = "false" TrackIDAudio = "5" ShortDescriptionLine1 = "short-form"/>
</AudioContent>

注意“TrackIDAudio”属性。

现在转到 HomeSceen.brs 文件并查看以下内容:

if m.audiolist.content.getChild(index).TrackIDAudio = m.contentId
                    m.audiolist.jumpToItem = index
                    m.audioPlayer.itemContent = m.audiolist.content.getChild(index)
                    m.audioPlayer.audioControl = "play"
                    m.audioPlayer.setFocus(true)
                    m.audioPlayer.visible = true 

                    exit for
end if

所以我在这里检查 m.contentId(这实际上是我们在 main.brs 文件中添加回 HomeScene 顶部的 args.contentId)是否与我的 LabelList 中的 TrackIDAudio 相同。如果它们相同,App 将播放我的项目!

有一件事,你可以用这个TOOL 测试你的深层链接。

此外,您现在应该需要发送您的 contentID 和 MediaTypes 的 Roku XML 提要,以便它们可以在发布时将这些项目与您的应用链接。

因此,用户在 Roku 搜索中单击您的项目,Roku 将您在 XML 提要中提供给他们的 contentId 和 MediaType 发送到 Roku 固件,ROKU 固件将 contentId 和 MediaType 放入 args 中,然后您执行您需要的操作用它。 深度链接工具模仿了这一点。

您还可以在 link 上找到有关深度链接的更多信息

***我的 audiocontent.xml 中有一个项目的链接错误。我是故意这样做的,所以我可以展示如果你播放损坏的链接会发生什么。因此,在使用 Repo 时请不要担心。

***请检查这个,关于你的问题的变化: 好的,你也可以这样做: 删除m.global.addFields({ input: input })这一行,加上这两行:

m.global.addFields({inputContentID: input.contentID})
m.global.addFields({inputMediaType: input.mediaType})

现在您可以检查此 m.global 变量是否为空,如果不是,您可以立即开始播放视频: 当视频播放器的内容准备好由视频播放器播放时,您可以检查此项:

if Len(m.global.inputContentID) > 0 AND Len(m.global.inputMediaType) > 0

        //loop through your content and find an item that has same inputContentID as the one saved in m.global.inputContentID variable.If you find it, play the video.

        m.Video.control = "play"

        m.global.inputContentID = ""
        m.global.inputMediaType = ""
end if

【讨论】:

  • 我的主频道使用视频模板,所以我的组件文件夹中甚至没有 HomeScreen.brs。我在将您的示例转换为视频模板示例时遇到了一些麻烦。我在想如果我能弄清楚如何正确地将参数传递给 video screen.show 函数,它可以工作吗?谢谢!
  • 嗨,我在上面的答案中添加了几行。希望对您有所帮助!
  • 很抱歉,我仍然无法将您的示例转换为视频示例。我尝试了几件事,但它们对我不起作用。尝试将代码添加到 SpringBoard.brs 或 VideoScene.brs 代码时,我会收到诸如“类型不匹配”或“使用未初始化的变量”之类的错误。我想我已经接近了,但它不适合我。
  • 你能告诉我你得到的是哪个变量“类型不匹配”或“使用未初始化的变量”吗?
  • @SteveLacy 你能告诉我哪个变量给你“使用未初始化的变量”或“类型不匹配”错误吗?
猜你喜欢
  • 2017-09-05
  • 1970-01-01
  • 2020-12-01
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
相关资源
最近更新 更多