Play selected Audio Stream rather than the default track

This commit is contained in:
Neil Burrows 2020-10-24 17:23:20 +01:00
parent f5ccdca744
commit 5cbe119002
5 changed files with 34 additions and 29 deletions

View File

@ -9,8 +9,6 @@ sub init()
overview.width = 1920 - 96 - 300 - 96 - 30
m.top.findNode("buttons").setFocus(true)
m.selectedAudioStreamIndex = 0
end sub
sub itemContentChanged()
@ -24,7 +22,7 @@ sub itemContentChanged()
' Find first Audio Stream and set that as default
For i=0 To itemData.mediaStreams.Count() - 1
if itemData.mediaStreams[i].Type = "Audio" then
m.selectedAudioStreamIndex = i
m.top.selectedAudioStreamIndex = i
exit for
end if
End For
@ -67,7 +65,7 @@ sub itemContentChanged()
setFieldText("director", tr("Director") + ": " + director)
end if
setFieldText("video_codec", tr("Video") + ": " + itemData.mediaStreams[0].displayTitle)
setFieldText("audio_codec", tr("Audio") + ": " + itemData.mediaStreams[m.selectedAudioStreamIndex].displayTitle)
setFieldText("audio_codec", tr("Audio") + ": " + itemData.mediaStreams[m.top.selectedAudioStreamIndex].displayTitle)
' TODO - cmon now. these are buttons, not words
if itemData.taglines.count() > 0
setFieldText("tagline", itemData.taglines[0])
@ -84,7 +82,7 @@ sub SetUpOptions(streams)
for i=0 To streams.Count() - 1
if streams[i].Type = "Audio" then
tracks.push({"Title": streams[i].displayTitle, "Description" : streams[i].Title, "Selected" : m.selectedAudioStreamIndex = i, "StreamIndex" : i})
tracks.push({"Title": streams[i].displayTitle, "Description" : streams[i].Title, "Selected" : m.top.selectedAudioStreamIndex = i, "StreamIndex" : i})
end if
end for
@ -171,9 +169,9 @@ end function
'
'Check if options updated and any reloading required
sub optionsClosed()
if m.options.audioSteamIndex <> m.selectedAudioStreamIndex then
m.selectedAudioStreamIndex = m.options.audioSteamIndex
setFieldText("audio_codec", tr("Audio") + ": " + m.top.itemContent.json.mediaStreams[m.selectedAudioStreamIndex].displayTitle)
if m.options.audioSteamIndex <> m.top.selectedAudioStreamIndex then
m.top.selectedAudioStreamIndex = m.options.audioSteamIndex
setFieldText("audio_codec", tr("Audio") + ": " + m.top.itemContent.json.mediaStreams[m.top.selectedAudioStreamIndex].displayTitle)
end if
m.top.findNode("buttons").setFocus(true)
end sub

View File

@ -39,6 +39,7 @@
</children>
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged" />
<field id="selectedAudioStreamIndex" type="integer" />
</interface>
<script type="text/brightscript" uri="pkg:/source/utils/misc.brs" />
<script type="text/brightscript" uri="MovieDetails.brs" />

View File

@ -334,10 +334,16 @@ sub Main()
' If a button is selected, we have some determining to do
btn = getButton(msg)
if btn.id = "play-button"
' Check is a specific Audio Stream was selected
audio_stream_idx = 1
if group.selectedAudioStreamIndex <> invalid
audio_stream_idx = group.selectedAudioStreamIndex
end if
' TODO - Do a better job of picking the last focus
' This is currently page layout Group, button Group, then button
video_id = group.id
video = CreateVideoPlayerGroup(video_id)
video = CreateVideoPlayerGroup(video_id, audio_stream_idx)
if video <> invalid then
group.lastFocus = group.focusedChild.focusedChild.focusedChild
group.setFocus(false)

View File

@ -357,9 +357,9 @@ function CreatePaginator()
return group
end function
function CreateVideoPlayerGroup(video_id)
function CreateVideoPlayerGroup(video_id, audio_stream_idx = 1)
' Video is Playing
video = VideoPlayer(video_id)
video = VideoPlayer(video_id, audio_stream_idx)
if video = invalid return invalid
timer = video.findNode("playbackTimer")

View File

@ -1,8 +1,8 @@
function VideoPlayer(id)
function VideoPlayer(id, audio_stream_idx = 1)
' Get video controls and UI
video = CreateObject("roSGNode", "JFVideo")
video.id = id
video = VideoContent(video)
video = VideoContent(video, audio_stream_idx)
if video = invalid
return invalid
end if
@ -14,7 +14,7 @@ function VideoPlayer(id)
return video
end function
function VideoContent(video) as object
function VideoContent(video, audio_stream_idx = 1) as object
' Get video stream
video.content = createObject("RoSGNode", "ContentNode")
params = {}
@ -60,7 +60,7 @@ function VideoContent(video) as object
container = getContainerType(meta)
video.container = container
transcodeParams = getTranscodeParameters(meta)
transcodeParams = getTranscodeParameters(meta, audio_stream_idx)
transcodeParams.append({"PlaySessionId": video.PlaySessionId})
if meta.live then
@ -84,7 +84,7 @@ function VideoContent(video) as object
video.SelectedSubtitle = -1
end if
if video.SelectedSubtitle <> -1 and displaySubtitlesByUserConfig(video.Subtitles[video.SelectedSubtitle], meta.json.MediaStreams[1]) then
if video.SelectedSubtitle <> -1 and displaySubtitlesByUserConfig(video.Subtitles[video.SelectedSubtitle], meta.json.MediaStreams[audio_stream_idx]) then
if video.Subtitles[0].IsTextSubtitleStream then
video.subtitleTrack = video.availableSubtitleTracks[video.Subtitles[0].TextIndex].TrackName
video.suppressCaptions = false
@ -104,14 +104,15 @@ function VideoContent(video) as object
end if
video.directPlaySupported = directPlaySupported(meta)
video.decodeAudioSupported = decodeAudioSupported(meta)
video.decodeAudioSupported = decodeAudioSupported(meta, audio_stream_idx)
video.transcodeParams = transcodeParams
if video.directPlaySupported and video.decodeAudioSupported and transcodeParams.SubtitleStreamIndex = invalid then
params.append({
"Static": "true",
"Container": container
"PlaySessionId": video.PlaySessionId
"Container": container,
"PlaySessionId": video.PlaySessionId,
"AudioStreamIndex": audio_stream_idx
})
video.content.url = buildURL(Substitute("Videos/{0}/stream", video.id), params)
video.content.streamformat = container
@ -130,13 +131,12 @@ function VideoContent(video) as object
end function
function getTranscodeParameters(meta as object)
function getTranscodeParameters(meta as object, audio_stream_idx = 1)
params = {}
if decodeAudioSupported(meta) and meta.json.MediaStreams[1] <> invalid and meta.json.MediaStreams[1].Type = "Audio" then
audioCodec = meta.json.MediaStreams[1].codec
audioChannels = meta.json.MediaStreams[1].channels
params = {"AudioStreamIndex": audio_stream_idx}
if decodeAudioSupported(meta, audio_stream_idx) and meta.json.MediaStreams[audio_stream_idx] <> invalid and meta.json.MediaStreams[audio_stream_idx].Type = "Audio" then
audioCodec = meta.json.MediaStreams[audio_stream_idx].codec
audioChannels = meta.json.MediaStreams[audio_stream_idx].channels
else
params.Append({"AudioCodec": "aac"})
@ -235,14 +235,14 @@ function directPlaySupported(meta as object) as boolean
return devinfo.CanDecodeVideo(streamInfo).result
end function
function decodeAudioSupported(meta as object) as boolean
function decodeAudioSupported(meta as object, audio_stream_idx = 1) as boolean
'Check for missing audio and allow playing
if meta.json.MediaStreams[1] = invalid or meta.json.MediaStreams[1].Type <> "Audio" then return true
if meta.json.MediaStreams[audio_stream_idx] = invalid or meta.json.MediaStreams[audio_stream_idx].Type <> "Audio" then return true
devinfo = CreateObject("roDeviceInfo")
codec = meta.json.MediaStreams[1].codec
streamInfo = { Codec: codec, ChCnt: meta.json.MediaStreams[1].channels }
codec = meta.json.MediaStreams[audio_stream_idx].codec
streamInfo = { Codec: codec, ChCnt: meta.json.MediaStreams[audio_stream_idx].channels }
'Otherwise check Roku can decode stream and channels
canDecode = devinfo.CanDecodeAudio(streamInfo)