2019-03-19 00:33:44 +00:00
|
|
|
function VideoPlayer(id)
|
2019-04-29 16:44:37 +00:00
|
|
|
' Get video controls and UI
|
2019-10-12 21:00:07 +00:00
|
|
|
video = CreateObject("roSGNode", "JFVideo")
|
2020-02-17 19:30:04 +00:00
|
|
|
video.id = id
|
|
|
|
video = VideoContent(video)
|
2020-02-15 15:34:29 +00:00
|
|
|
|
2019-03-19 00:33:44 +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
|
|
|
|
|
2020-02-17 19:30:04 +00:00
|
|
|
function VideoContent(video) as object
|
2019-04-29 16:44:37 +00:00
|
|
|
' Get video stream
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content = createObject("RoSGNode", "ContentNode")
|
2019-01-31 04:56:15 +00:00
|
|
|
|
2020-02-17 19:30:04 +00:00
|
|
|
meta = ItemMetaData(video.id)
|
|
|
|
video.content.title = meta.Name
|
2019-04-22 05:09:16 +00:00
|
|
|
container = getContainerType(meta)
|
2020-02-22 00:50:20 +00:00
|
|
|
|
|
|
|
' If there is a last playback positon, ask user if they want to resume
|
|
|
|
position = meta.json.UserData.PlaybackPositionTicks
|
|
|
|
if position > 0 and startPlaybackOver(position) then
|
|
|
|
position = 0
|
|
|
|
end if
|
|
|
|
video.content.BookmarkPosition = int(position/10000000)
|
|
|
|
|
|
|
|
video.PlaySessionId = ItemGetSession(video.id, position)
|
2020-02-15 15:34:29 +00:00
|
|
|
|
2020-02-21 04:02:21 +00:00
|
|
|
if directPlaySupported(meta) and decodeAudioSupported(meta) then
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content.url = buildURL(Substitute("Videos/{0}/stream", video.id), {
|
|
|
|
"PlaySessionId": video.PlaySessionId
|
2020-02-15 15:23:11 +00:00
|
|
|
Static: "true",
|
2020-02-15 15:26:36 +00:00
|
|
|
Container: container
|
|
|
|
})
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content.streamformat = container
|
|
|
|
video.content.switchingStrategy = ""
|
2020-02-15 01:47:06 +00:00
|
|
|
else
|
2020-02-22 01:49:22 +00:00
|
|
|
|
|
|
|
if decodeAudioSupported(meta) then
|
|
|
|
audioCodec = meta.json.MediaStreams[1].codec
|
2020-02-21 04:02:21 +00:00
|
|
|
audioChannels = meta.json.MediaStreams[1].channels
|
2020-02-22 01:49:22 +00:00
|
|
|
else
|
|
|
|
audioCodec = "aac"
|
|
|
|
audioChannels = 2
|
2020-02-21 04:02:21 +00:00
|
|
|
end if
|
|
|
|
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content.url = buildURL(Substitute("Videos/{0}/master.m3u8", video.id), {
|
|
|
|
"PlaySessionId": video.PlaySessionId
|
|
|
|
"VideoCodec": "h264",
|
2020-02-22 01:49:22 +00:00
|
|
|
"AudioCodec": audioCodec,
|
2020-02-21 04:02:21 +00:00
|
|
|
"MaxAudioChannels": audioChannels,
|
2020-02-17 19:30:04 +00:00
|
|
|
"MediaSourceId": video.id,
|
|
|
|
"SegmentContainer": "ts",
|
|
|
|
"MinSegments": 1,
|
|
|
|
"BreakOnNonKeyFrames": "True",
|
|
|
|
"h264-profile": "high,main,baseline,constrainedbaseline",
|
|
|
|
"RequireAvc": "false",
|
2020-02-15 15:26:36 +00:00
|
|
|
})
|
2020-02-15 01:47:06 +00:00
|
|
|
end if
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content = authorize_request(video.content)
|
2019-01-31 04:56:15 +00:00
|
|
|
|
2019-04-22 05:09:16 +00:00
|
|
|
' todo - audioFormat is read only
|
2020-02-17 19:30:04 +00:00
|
|
|
video.content.audioFormat = getAudioFormat(meta)
|
2020-02-19 08:47:29 +00:00
|
|
|
video.content.setCertificatesFile("common:/certs/ca-bundle.crt")
|
2020-02-15 15:34:29 +00:00
|
|
|
|
2020-02-17 19:30:04 +00:00
|
|
|
return video
|
2019-01-31 04:56:15 +00:00
|
|
|
end function
|
2019-04-22 05:09:16 +00:00
|
|
|
|
2020-02-22 00:50:20 +00:00
|
|
|
'Opens dialog asking user if they want to resume video or start playback over
|
|
|
|
function startPlayBackOver(time as LongInteger) as boolean
|
|
|
|
return option_dialog([ "Resume playing at " + ticksToHuman(time) + ".", "Start over from the begining." ])
|
|
|
|
end function
|
|
|
|
|
2020-02-15 01:47:06 +00:00
|
|
|
function directPlaySupported(meta as object) as boolean
|
2020-02-21 04:02:21 +00:00
|
|
|
devinfo = CreateObject("roDeviceInfo")
|
|
|
|
return devinfo.CanDecodeVideo({ Codec: meta.json.MediaStreams[0].codec }).result
|
|
|
|
end function
|
|
|
|
|
|
|
|
function decodeAudioSupported(meta as object) as boolean
|
|
|
|
devinfo = CreateObject("roDeviceInfo")
|
|
|
|
return devinfo.CanDecodeAudio({ Codec: meta.json.MediaStreams[1].codec, ChCnt: meta.json.MediaStreams[1].channels }).result
|
2020-02-15 01:47:06 +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
|
2019-04-22 19:08:10 +00:00
|
|
|
print type(meta)
|
2019-04-22 05:09:16 +00:00
|
|
|
if meta.json.mediaSources = invalid then return ""
|
|
|
|
|
|
|
|
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
|
2020-02-17 19:30:04 +00:00
|
|
|
|
|
|
|
function ReportPlayback(video, state = "update" as string)
|
|
|
|
params = {
|
|
|
|
"PlaySessionId": video.PlaySessionId,
|
2020-02-21 04:02:21 +00:00
|
|
|
"PositionTicks": str(int(video.position)) + "0000000",
|
2020-02-17 19:30:04 +00:00
|
|
|
"IsPaused": (video.state = "paused"),
|
|
|
|
}
|
|
|
|
PlaystateUpdate(video.id, state, params)
|
|
|
|
end function
|
|
|
|
|
|
|
|
function StopPlayback()
|
|
|
|
video = m.scene.focusedchild
|
|
|
|
video.findNode("playbackTimer").control = "stop"
|
|
|
|
video.control = "stop"
|
|
|
|
video.visible = "false"
|
|
|
|
if video.status = "finished" then MarkItemWatched(video.id)
|
2020-02-21 04:02:21 +00:00
|
|
|
ReportPlayback(video, "stop")
|
2020-02-17 19:30:04 +00:00
|
|
|
end function
|