diff --git a/.gitignore b/.gitignore index fa001aa..f86df33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ out/ out/roku-deploy.zip +.history/ +.vscode/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index dca2ab3..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "brightscript", - "request": "launch", - "name": "BrightScript Debug: Launch", - "stopOnEntry": false, - "host": "${promptForHost}", - "password": "mega", - "rootDir": "${workspaceFolder}", - "enableDebuggerAutoRecovery": false, - "stopDebuggerOnAppExit": false - } - ] -} \ No newline at end of file diff --git a/components/keyboardScene.brs b/components/keyboardScene.brs new file mode 100644 index 0000000..1905668 --- /dev/null +++ b/components/keyboardScene.brs @@ -0,0 +1,155 @@ +sub init() + m.keyboard = m.top.findNode("myKeyboard") + m.itemsList = m.top.findNode("searchList") + m.video = m.top.findNode("video") + m.itemsList.observeField("itemSelected", "handleItemSelected") + m.heading = m.top.findNode("heading") + m.keyboard.setFocus(true) + m.keyboard.observeField("text", "handleText") + m.http = createObject("roSGNode", "httpTask") + m.http.observeFieldScoped("response", "useResponse") + m.keyboard.textBox.observeField("text", "handleText") + m.keyboard.observeField("submit", "handleSubmit") +end sub + +sub handleText() + m.text = m.keyboard.textBox.text +end sub + +sub handleSubmit() + handleVideoPlaybackResponse() + + ' m.http.request = { payload: { + ' userId: 1, + ' title: "WOW, IT WORKED ^_^", + ' }, url: "https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=" + m.text + "&maxResults=25&type=video&key=AIzaSyCxEpZ8-3gkiFpoc2SAkPBfcPFqQd6m_dw", requestType: "GET" } + ' m.http.control = "RUN" +end sub + +sub useResponse() + m.itemsThatContainString = createObject("roSGNode", "ContentNode") + items = [] + m.itemsList.numColumns = 3 + for each item in parseJson(m.http.response.body).items + Content = m.itemsThatContainString.createChild("ContentNode") + Content.HDPosterUrl = item.snippet.thumbnails.medium.url + Content.id = item.id.videoId + items.push(item) + end for + if items.count() = 2 + m.itemsList.numColumns = 2 + else if items.count() = 1 + m.itemsList.numColumns = 1 + end if + ' handle empty text box + if m.keyboard.textBox.text = "" + m.itemsList.content = invalid + m.heading.visible = false + else + m.heading.visible = true + m.itemsList.content = m.itemsThatContainString + handleHeading() + end if +end sub + +sub handleHeading() + m.heading.text = "These are the top videos that match " + Chr(34) + m.keyboard.textBox.text + Chr(34) +end sub + +sub handleItemSelected() + ' http://scienceandfilm.org/uploads/videos/files/afronauts_trailer.mp4 + ' playVideo(m.itemsThatContainString.getChild(m.itemsList.itemSelected).id) +end sub + +function onKeyEvent(key as String, press as Boolean) as Boolean + if press and m.keyboard.visible = true + if key = "right" and not m.itemsList.hasFocus() + m.itemsList.setFocus(true) + return true + else if key = "left" and not m.keyboard.hasFocus() + m.keyboard.setFocus(true) + end if + end if + return false +end function + +sub playVideo(id as String) + ' m.videoPlaybackTask = createObject("roSGNode", "httpTask") + ' m.videoPlaybackTask.request = { payload: { + ' userId: 1, + ' title: "WOW, IT WORKED ^_^", + ' }, url: "https://www.youtube.com/watch?v=" + id, requestType: "GET" } + ' m.videoPlaybackTask.control = "RUN" + ' m.videoPlaybackTask.observeFieldScoped("response", "handleVideoPlaybackResponse") +end sub + +sub handleVideoPlaybackResponse() + ' initialPlayerResponseRegEx = createObject("roRegex", "ytInitialPlayerResponse\s*=\s*({.+?})\s*;", "m") + ' matches = initialPlayerResponseRegEx.match(m.videoPlaybackTask.response.body) + videoContent = createObject("RoSGNode", "ContentNode") + ' YouTube API Limit Exceeded + ' videoContent.url = parseJson(matches[1]).streamingData.formats[0].url + videoContent.url = "https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/m3u8s/11331.m3u8" + videoContent.streamFormat = "hls" + videoContent.drmParams = { + name: "Vertimatrix", + authDomain: "https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==", + serializationUrl: "https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==" + } + m.video.content = videoContent + m.video.visible = true + m.video.enableUI = false + m.video.enableTrickPlay = false + m.video.createChild("TrickPlay") + m.keyboard.visible = false + m.video.seekMode = "accurate" + m.video.setFocus(true) + m.video.control = "play" + m.video.getChild(2).setFocus(true) + m.video.getChild(2).observeField("play", "handlePlay") + m.video.getChild(2).observeField("forward", "handleForward") + m.video.getChild(2).observeField("back", "handleBack") + m.video.getChild(2).observeField("cc", "handleCC") + m.video.observeField("state", "videoStarted") + m.video.observeField("position", "updatePosition") + m.video.observeField("bufferingStatus", "updateBuffering") +end sub + +sub updateBuffering() + if m.video.bufferingStatus <> invalid + m.video.getChild(2).loadingData = { percentage: m.video.bufferingStatus.percentage, done: m.video.bufferingStatus.prebufferDone } + end if +end sub + +sub updatePosition() + m.video.getChild(2).position = m.video.position +end sub + +sub videoStarted() + m.video.getChild(2).duration = m.video.duration +end sub + +sub handlePlay() + if m.video.control = "play" or m.video.control = "resume" + m.video.control = "pause" + else + m.video.control = "resume" + end if + if m.video.state = "finished" + m.video.control = "play" + end if +end sub + +sub handleForward() + m.video.seek = m.video.position + 15 + m.video.control = "resume" +end sub + +sub handleBack() + m.video.seek = m.video.position - 15 + m.video.control = "resume" +end sub + +sub handleCC() + +end sub \ No newline at end of file diff --git a/components/keyboardScene.xml b/components/keyboardScene.xml new file mode 100644 index 0000000..c4719b0 --- /dev/null +++ b/components/keyboardScene.xml @@ -0,0 +1,12 @@ + + +