如何在Roku VideoPlayer示例频道

时间:2017-12-14 22:33:41

标签: deep-linking roku

我们使用Roku VideoPlayer示例频道(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评论说

  

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

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

我对Roku开发还不熟悉。虽然我们之前已经能够使用他们的视频频道模板创建频道,但我不知道如何启动/准备映射到contentID"的内容。我已经搜索并尝试了其他各种调用(例如 - playMedia(ContentID, Screen)),但是我在调​​试器上遇到与"函数调用operator()在非函数"上尝试的错误。

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

这是我的主要人物:

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值,但它只是进入主屏幕而没有提示深层链接的视频。

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

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

小解释: 首先,我在我的main.brs中这样:

sub Main(args as Dynamic) as Void

    showSGScreen(args)
end sub

&#34; ARGS&#34;将由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>

注意&#34; TrackIDAudio&#34;属性。

现在转到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相同。如果它们是相同的,应用程序将播放我的项目!

有一件事,您可以使用此TOOL测试深层链接。

此外,您现在应该需要发送contentID和MediaType的Roku XML Feed,以便他们可以在发布时将这些项目与您的应用相关联。

因此,用户在Roku搜索中点击您的项目,Roku将您提供给他们的contentId和MediaType发送到Roku固件,ROKU固件,而不是将contentId和MediaType放入args中,之后你随心所欲地做你需要的。 深层链接工具模仿了这一点。

您还可以在此link

上找到有关深层链接的更多信息

***我的audiocontent.xml中的一个项目链接不正确。我故意这样做,所以我可以展示如果你播放损坏的链接将会发生什么。因此,在玩回购时请不要担心。

***请检查一下,关于您问题的变化: 好的,你可以像这样做: 删除此行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