jf-roku/source/VideoPlayer.brs

84 lines
2.0 KiB
Plaintext
Raw Normal View History

function VideoPlayer(id)
2019-04-29 16:44:37 +00:00
' Get video controls and UI
video = CreateObject("roSGNode", "Video")
2019-03-05 04:59:31 +00:00
content = VideoContent(id)
2019-01-31 04:56:15 +00:00
2019-03-05 04:59:31 +00:00
video.setFocus(true)
video.content = content
2019-03-05 04:59:31 +00:00
video.control = "play"
2019-01-31 04:56:15 +00:00
jellyfin_blue = "#00a4dcFF"
video.retrievingBar.filledBarBlendColor = jellyfin_blue
video.bufferingBar.filledBarBlendColor = jellyfin_blue
video.trickPlayBar.filledBarBlendColor = jellyfin_blue
2019-03-05 04:59:31 +00:00
return video
2019-01-31 04:56:15 +00:00
end function
function VideoContent(id) as object
2019-04-29 16:44:37 +00:00
' Get video stream
2019-03-05 05:18:01 +00:00
content = createObject("RoSGNode", "ContentNode")
2019-01-31 04:56:15 +00:00
2019-03-05 05:18:01 +00:00
meta = ItemMetaData(id)
content.title = meta.Name
2019-01-31 04:56:15 +00:00
2019-04-22 05:09:16 +00:00
container = getContainerType(meta)
content.url = buildURL(Substitute("Videos/{0}/stream", id), {
Static: "true",
Container: container
})
2019-01-31 04:56:15 +00:00
2019-03-05 05:18:01 +00:00
content = authorize_request(content)
2019-01-31 04:56:15 +00:00
content.streamformat = container
content.switchingStrategy = ""
2019-04-22 05:09:16 +00:00
' todo - audioFormat is read only
content.audioFormat = getAudioFormat(meta)
2019-03-05 05:18:01 +00:00
if server_is_https() then
content.setCertificatesFile("common:/certs/ca-bundle.crt")
end if
2019-01-31 04:56:15 +00:00
2019-03-05 05:18:01 +00:00
return content
2019-01-31 04:56:15 +00:00
end function
2019-04-22 05:09:16 +00:00
function getContainerType(meta as object) as string
2019-04-29 16:44:37 +00:00
' Determine the file type of the video file source
print type(meta)
2019-04-22 05:09:16 +00:00
if meta.json.mediaSources = invalid then return ""
2019-04-22 05:09:16 +00:00
container = meta.json.mediaSources[0].container
if container = invalid
container = ""
else if container = "m4v" or container = "mov"
container = "mp4"
end if
return container
end function
function getAudioFormat(meta as object) as string
2019-04-29 16:44:37 +00:00
' Determine the codec of the audio file source
2019-04-22 05:09:16 +00:00
if meta.json.mediaSources = invalid then return ""
audioInfo = getAudioInfo(meta)
if audioInfo.count() = 0 then return ""
return audioInfo[0].codec
end function
function getAudioInfo(meta as object) as object
2019-04-29 16:44:37 +00:00
' Return audio metadata for a given stream
2019-04-22 05:09:16 +00:00
results = []
for each source in meta.json.mediaSources[0].mediaStreams
if source["type"] = "Audio"
results.push(source)
end if
end for
return results
end function