2019-03-18 19:33:44 -05:00
|
|
|
function VideoPlayer(id)
|
2019-04-29 12:44:37 -04:00
|
|
|
' Get video controls and UI
|
2019-10-12 16:00:07 -05:00
|
|
|
video = CreateObject("roSGNode", "JFVideo")
|
|
|
|
video.content = VideoContent(id)
|
2020-02-15 07:23:11 -08:00
|
|
|
|
2019-03-18 19:33:44 -05:00
|
|
|
jellyfin_blue = "#00a4dcFF"
|
|
|
|
|
|
|
|
video.retrievingBar.filledBarBlendColor = jellyfin_blue
|
|
|
|
video.bufferingBar.filledBarBlendColor = jellyfin_blue
|
|
|
|
video.trickPlayBar.filledBarBlendColor = jellyfin_blue
|
2019-03-04 22:59:31 -06:00
|
|
|
return video
|
2019-01-30 22:56:15 -06:00
|
|
|
end function
|
|
|
|
|
|
|
|
function VideoContent(id) as object
|
2019-04-29 12:44:37 -04:00
|
|
|
' Get video stream
|
2019-03-04 23:18:01 -06:00
|
|
|
content = createObject("RoSGNode", "ContentNode")
|
2019-01-30 22:56:15 -06:00
|
|
|
|
2020-02-14 17:47:06 -08:00
|
|
|
meta = ItemMetaData(id)
|
2019-03-04 23:18:01 -06:00
|
|
|
content.title = meta.Name
|
2019-04-22 00:09:16 -05:00
|
|
|
container = getContainerType(meta)
|
2020-02-14 17:47:06 -08:00
|
|
|
|
|
|
|
if directPlaySupported(meta) then
|
2020-02-15 07:26:36 -08:00
|
|
|
content.url = buildURL(Substitute("Videos/{0}/stream", id), {
|
2020-02-15 07:23:11 -08:00
|
|
|
Static: "true",
|
2020-02-15 07:26:36 -08:00
|
|
|
Container: container
|
|
|
|
})
|
|
|
|
content.streamformat = container
|
|
|
|
content.switchingStrategy = ""
|
2020-02-14 17:47:06 -08:00
|
|
|
else
|
2020-02-15 07:26:36 -08:00
|
|
|
content.url = buildURL(Substitute("Videos/{0}/master.m3u8", id), {
|
|
|
|
PlaySessionId: ItemGetSession(id)
|
|
|
|
VideoCodec: "h264",
|
|
|
|
AudioCodec: "aac",
|
|
|
|
MediaSourceId: id,
|
|
|
|
})
|
2020-02-14 17:47:06 -08:00
|
|
|
end if
|
2019-03-04 23:18:01 -06:00
|
|
|
content = authorize_request(content)
|
2019-01-30 22:56:15 -06:00
|
|
|
|
2019-04-22 00:09:16 -05:00
|
|
|
' todo - audioFormat is read only
|
|
|
|
content.audioFormat = getAudioFormat(meta)
|
2020-02-14 17:47:06 -08:00
|
|
|
|
2019-03-04 23:18:01 -06:00
|
|
|
if server_is_https() then
|
|
|
|
content.setCertificatesFile("common:/certs/ca-bundle.crt")
|
|
|
|
end if
|
|
|
|
return content
|
2019-01-30 22:56:15 -06:00
|
|
|
end function
|
2019-04-22 00:09:16 -05:00
|
|
|
|
2020-02-14 17:47:06 -08:00
|
|
|
function directPlaySupported(meta as object) as boolean
|
|
|
|
devinfo = CreateObject("roDeviceInfo")
|
|
|
|
return devinfo.CanDecodeVideo({ Codec: meta.json.MediaStreams[0].codec }).result
|
|
|
|
end function
|
|
|
|
|
2019-04-22 00:09:16 -05:00
|
|
|
function getContainerType(meta as object) as string
|
2019-04-29 12:44:37 -04:00
|
|
|
' Determine the file type of the video file source
|
2019-04-22 14:08:10 -05:00
|
|
|
print type(meta)
|
2019-04-22 00:09:16 -05:00
|
|
|
if meta.json.mediaSources = invalid then return ""
|
|
|
|
|
2019-04-22 14:08:10 -05:00
|
|
|
|
2019-04-22 00:09:16 -05: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 12:44:37 -04:00
|
|
|
' Determine the codec of the audio file source
|
2019-04-22 00:09:16 -05: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 12:44:37 -04:00
|
|
|
' Return audio metadata for a given stream
|
2019-04-22 00:09:16 -05: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
|