如何使用BrightScript for Roku创建YouTube式视频播放器?

如何使用BrightScript for Roku创建YouTube式视频播放器?,youtube,video-player,roku,brightscript,Youtube,Video Player,Roku,Brightscript,我是ROKU开发的新手。几天前我就知道了。我想为我的Roku设备创建一个具有Youtube外观的视频播放器。我希望我的视频播放器以小窗口模式启动,并像Youtube那样在右侧显示视频列表。此外,我还想添加一个按钮来最大化和最小化屏幕 我已经研究过了。我尝试了Brighscript sdk附带的视频播放器示例。我也尝试过使用一些在线的定制视频播放器示例,但没有帮助实现我想要的。 如何在bright script视频播放器上添加按钮,以及如何制作该按钮以最小化和最大化bright script中的窗

我是ROKU开发的新手。几天前我就知道了。我想为我的Roku设备创建一个具有Youtube外观的视频播放器。我希望我的视频播放器以小窗口模式启动,并像Youtube那样在右侧显示视频列表。此外,我还想添加一个按钮来最大化和最小化屏幕

我已经研究过了。我尝试了Brighscript sdk附带的视频播放器示例。我也尝试过使用一些在线的定制视频播放器示例,但没有帮助实现我想要的。 如何在bright script视频播放器上添加按钮,以及如何制作该按钮以最小化和最大化bright script中的窗口。有人能为我提供相关代码吗??

我已经下载了使用rovideoplayer的自定义视频播放器。 以下是Main.brs代码:

Sub RunUserInterface()
    o = Setup()
    o.setup()
    o.paint()
    o.eventloop()
End Sub

Sub Setup() As Object
    this = {
        port:      CreateObject("roMessagePort")
        progress:  0 'buffering progress
        position:  0 'playback position (in seconds)
        paused:    false 'is the video currently paused?
        feedData:  invalid
        playing:   0
        playingPrev: 0
        playlistSize: 0
        canvas:    CreateObject("roImageCanvas") 'user interface
        player:    CreateObject("roVideoPlayer")
        load:      LoadFeed
        setup:     SetupFullscreenCanvas
        paint:     PaintFullscreenCanvas
        create_playlist_text: CreatePlaylistText
        drawtext:  false
        eventloop: EventLoop
    }
 this.targetRect ={x: 350, y: 100, w: 600, h:500}
  '  this.targetRect = this.canvas.GetCanvasRect()
    this.textRect = {x: 520, y: 480, w: 300, h:200} 

    this.load()
    'Setup image canvas:
    this.canvas.SetMessagePort(this.port)
    this.canvas.SetLayer(0, { Color: "#000000" })
    this.canvas.Show()

    this.player.SetMessagePort(this.port)
    this.player.SetLoop(true)
    this.player.SetPositionNotificationPeriod(1)
    this.player.SetDestinationRect(this.targetRect)

    this.player.Play()
    this.playingPrev = this.playing

    return this
End Sub

Sub EventLoop()
    while true
        msg = wait(0, m.port)
        if msg <> invalid
            if msg.isStatusMessage() and msg.GetMessage() = "startup progress"
                m.paused = false
                print "Raw progress: " + stri(msg.GetIndex())
                progress% = msg.GetIndex() / 10
                if m.progress <> progress%
                    m.progress = progress%
                    m.paint()
                end if

            'Playback progress (in seconds):
            else if msg.isPlaybackPosition()
                m.position = msg.GetIndex()
                print "Playback position: " + stri(m.position)

            else if msg.isRemoteKeyPressed()
                index = msg.GetIndex()
                print "Remote button pressed: " + index.tostr()
                if index = 4  '<LEFT>
                    m.playing = m.playing - 1
                    if (m.playing < 0)
                        m.playing = 2
                    endif
                    m.player.SetNext(m.playing)
                    m.player.Play()
                    m.playingPrev = m.playing
                else if index = 8 '<REV>
                    m.position = m.position - 60
                    m.player.Seek(m.position * 1000)                
                else if index = 5 '<RIGHT>
                    m.playing = m.playing + 1
                    if (m.playing > 2)
                        m.playing = 0
                    endif
                    m.player.SetNext(m.playing)                    
                    m.player.Play()
                    m.playingPrev = m.playing                    
                else if index = 9 '<REV>
                    m.position = m.position + 60
                    m.player.Seek(m.position * 1000)
                else if index = 2 '<Up>
                    if m.drawtext
                        m.playing = m.playing - 1
                        if (m.playing < 0)
                            m.playing = m.playlistSize-1
                        endif
                        m.paint()
                    endif                
                else if index = 3 '<Down>
                    if m.drawtext
                        m.playing = m.playing + 1
                        if (m.playing > m.playlistSize-1)
                            m.playing = 0
                        endif
                        m.paint()
                    endif                
                else if index = 13  '<PAUSE/PLAY>
                    if m.paused m.player.Resume() else m.player.Pause()
                else if index = 6 'OK
                    if m.drawtext
                       m.drawtext = false                   
                       if m.playing <> m.playingPrev
                            m.player.SetNext(m.playing)                     
                          m.player.Play()
                          m.playingPrev = m.playing
                       endif
                    else
                        m.drawtext = true
                    endif
                    m.paint()
                end if

            else if msg.isPaused()
                m.paused = true
                m.paint()

            else if msg.isResumed()
                m.paused = false
                m.paint()

            end if
        endif
    end while
End Sub

Sub SetupFullscreenCanvas()
    m.canvas.AllowUpdates(false)
    m.paint()
    m.canvas.AllowUpdates(true)
End Sub

Sub PaintFullscreenCanvas()
    splash = []
    list = []

    if m.progress < 100
        progress_bar = {TargetRect: {x: 350, y: 500, w: 598, h: 37}, url: "pkg:/images/progress_bar.png"}
        color = "#00a0a0a0"
        splash.Push({
            url: "pkg:/images/splash.png"
            TargetRect: m.targetRect
        })
        list.Push({
            Text: "Loading..."
            TextAttrs: { font: "large", color: "#707070" }
            TargetRect: m.textRect
        })        
        if m.progress >= 0 AND m.progress < 20
            progress_bar.url = "pkg:/images/progress_bar_1.png"
            print progress_bar.url
        else if m.progress >= 20 AND m.progress < 40
            progress_bar.url = "pkg:/images/progress_bar_2.png"
            print progress_bar.url
        else if m.progress >= 40 AND m.progress < 75
            progress_bar.url = "pkg:/images/progress_bar_3.png"
            print progress_bar.url
        else
            progress_bar.url = "pkg:/images/progress_bar_4.png"
            print progress_bar.url            
        endif
        list.Push(progress_bar)

    end if

    if m.drawtext
       textArr = m.create_playlist_text()
       yTxt = 100
        color = "#00000000"
        index = 0
        for each str in textArr
            if index = m.playing
              textColor = "#00ff00"
            else
              textColor = "#dddddd"
            endif
            list.Push({
                Text: str
                TextAttrs: {color: textColor, font: "medium"}
                TargetRect: {x:200, y:yTxt, w: 500, h: 100}
            })
            yTxt = yTxt + 100
            index = index + 1
        end for
    else
        color = "#00000000"
        list.Push({
            Text: ""
            TextAttrs: {font: "medium"}
            TargetRect: {x:100, y:600, w: 300, h: 100}
        })
    endif

    'Clear previous contents
    m.canvas.ClearLayer(0)
    m.canvas.ClearLayer(1)
    m.canvas.ClearLayer(2)    
    m.canvas.SetLayer(0, { Color: color, CompositionMode: "Source" })
    if (splash.Count() > 0)
        m.canvas.SetLayer(1, splash)
        m.canvas.SetLayer(2, list)
    else
        m.canvas.SetLayer(1, list)
    endif
    list.Clear()
    splash.Clear()
End Sub

Function LoadFeed() as void
    jsonAsString = ReadAsciiFile("pkg:/json/feed.json")
    m.feedData = ParseJSON(jsonAsString)
    m.playlistSize = m.feedData.Videos.Count()
    contentList = []
    for each video in m.feedData.Videos
        contentList.Push({
            Stream: { url: video.url }
            StreamFormat: "mp4"
        })
    end for    
    m.player.SetContentList(contentList)    
End Function

Function CreatePlaylistText() as object
    textArr = []
    for each video in m.feedData.Videos
        textArr.Push(video.title)
    end for
    return textArr
End Function
Sub-RunUserInterface()
o=设置()
o、 设置()
o、 油漆()
o、 eventloop()
端接头
子设置()作为对象
这={
端口:CreateObject(“roMessagePort”)
进度:0'缓冲进度
位置:0'播放位置(秒)
暂停:false“视频当前是否暂停?”?
feedData:无效
播放:0
播放预览:0
播放列表大小:0
画布:CreateObject(“roImageCanvas”)用户界面
播放器:CreateObject(“roVideoPlayer”)
加载:加载提要
设置:SetupFullscreenCanvas
绘画:绘画全屏画布
创建播放列表文本:创建播放文本
drawtext:false
eventloop:eventloop
}
this.targetect={x:350,y:100,w:600,h:500}
'this.targetRect=this.canvas.GetCanvasRect()
this.textRect={x:520,y:480,w:300,h:200}
this.load()
'设置图像画布:
this.canvas.SetMessagePort(this.port)
this.canvas.SetLayer(0,{Color:#000000})
this.canvas.Show()
this.player.SetMessagePort(this.port)
this.player.SetLoop(true)
this.player.SetPositionNotificationPeriod(1)
this.player.SetDestinationRect(this.targetRect)
this.player.Play()
this.playingPrev=this.playing
还这个
端接头
子事件循环()
虽然是真的
msg=等待(0,m.port)
如果消息无效
如果msg.isStatusMessage()和msg.GetMessage()=“启动进度”
m、 暂停=错误
打印“原始进度:”+stri(msg.GetIndex())
进度%=msg.GetIndex()/10
如果m.进度%
m、 进度=进度%
m、 油漆()
如果结束
'播放进度(秒):
如果消息为msg.isPlaybackPosition()
m、 position=msg.GetIndex()
打印“播放位置:”+stri(m位置)
否则,如果msg.isRemoteKeyPressed()
index=msg.GetIndex()
打印“按下遥控按钮:”+index.tostr()
如果索引=4'
m、 playing=m.playing-1
如果(m.播放<0)
m、 播放=2
恩迪夫
m、 player.SetNext(m.playing)
m、 player.Play()
m、 playingPrev=m.playing
如果索引=8'
m、 位置=米。位置-60
m、 玩家搜索(m位置*1000)
如果索引=5'
m、 播放=m.播放+1
如果(m.播放>2)
m、 播放=0
恩迪夫
m、 player.SetNext(m.playing)
m、 player.Play()
m、 playingPrev=m.playing
如果索引=9'
m、 位置=米。位置+60
m、 玩家搜索(m位置*1000)
如果索引=2'
如果m.drawtext
m、 playing=m.playing-1
如果(m.播放<0)
m、 播放=m.playlistze-1
恩迪夫
m、 油漆()
恩迪夫
如果索引=3'
如果m.drawtext
m、 播放=m.播放+1
如果(m.播放>m.播放大小-1)
m、 播放=0
恩迪夫
m、 油漆()
恩迪夫
如果索引=13'
如果m.Pause m.player.Resume(),否则m.player.Pause()
否则,如果索引=6'正常
如果m.drawtext
m、 drawtext=false
如果m.playing m.playingPrev
m、 player.SetNext(m.playing)
m、 player.Play()
m、 playingPrev=m.playing
恩迪夫
其他的
m、 drawtext=true
恩迪夫
m、 油漆()
如果结束
如果msg.isPaused()
m、 暂停=真
m、 油漆()
如果msg.isResumed()
m、 暂停=错误
m、 油漆()
如果结束
恩迪夫
结束时
端接头
子设置FullScreenCanvas()
m、 canvas.allowUpdate(false)
m、 油漆()
m、 canvas.allowUpdate(true)
端接头
Sub-PaintFullscreenCanvas()
飞溅=[]
列表=[]
如果m.progress<100
progress_-bar={targetect:{x:350,y:500,w:598,h:37},url:“pkg:/images/progress_-bar.png”}
color=“#00A0”
飞溅,推({
url:“pkg:/images/splash.png”