Add audio track selection to video player

This commit is contained in:
1hitsong 2023-11-20 15:55:15 -05:00
parent a64dc4a9a2
commit 9e010f50b2
7 changed files with 104 additions and 1 deletions

View File

@ -131,6 +131,7 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
end if
addSubtitlesToVideo(video, meta)
addAudioStreamsToVideo(video)
if meta.live
video.transcodeParams = {
@ -219,6 +220,23 @@ sub addVideoContentURL(video, mediaSourceId, audio_stream_idx, fully_external)
end if
end sub
' addAudioStreamsToVideo: Add audio stream data to video
'
' @param {dynamic} video component to add fullAudioData to
sub addAudioStreamsToVideo(video)
audioStreams = []
mediaStreams = m.playbackInfo.MediaSources[0].MediaStreams
for i = 0 to mediaStreams.Count() - 1
if LCase(mediaStreams[i].Type) = "audio"
audioStreams.push(mediaStreams[i])
end if
end for
video.fullAudioData = audioStreams
end sub
sub addSubtitlesToVideo(video, meta)
subtitles = sortSubtitles(meta.id, m.playbackInfo.MediaSources[0].MediaStreams)
safesubs = subtitles["all"]

View File

@ -109,7 +109,8 @@ sub onContentDataChanged()
m.radioOptions.selectedIndex = i
end if
textLine = cardItem.CreateChild("SimpleLabel")
textLine = cardItem.CreateChild("ScrollingLabel")
textLine.maxWidth = "750"
textLine.text = item.track.description
cardItem.observeField("selected", "onItemSelected")
i++

View File

@ -14,6 +14,7 @@ sub CreateVideoPlayerView()
m.view.observeField("state", "onStateChange")
m.view.observeField("selectPlaybackInfoPressed", "onSelectPlaybackInfoPressed")
m.view.observeField("selectSubtitlePressed", "onSelectSubtitlePressed")
m.view.observeField("selectAudioPressed", "onSelectAudioPressed")
mediaSourceId = m.global.queueManager.callFunc("getCurrentItem").mediaSourceId
@ -32,6 +33,36 @@ end sub
' Event Handlers
' -----------------
' onSelectAudioPressed: Display audio selection dialog
'
sub onSelectAudioPressed()
audioData = {
data: []
}
for each item in m.view.fullAudioData
audioStreamItem = {
"Index": item.Index,
"IsExternal": item.IsExternal,
"Track": {
"description": item.DisplayTitle
},
"Type": "audioselection"
}
if m.view.audioIndex = item.Index
audioStreamItem.selected = true
end if
audioData.data.push(audioStreamItem)
end for
m.global.sceneManager.callFunc("radioDialog", tr("Select Audio"), audioData)
m.global.sceneManager.observeField("returnData", "onSelectionMade")
end sub
' User requested subtitle selection popup
sub onSelectSubtitlePressed()
' None is always first in the subtitle list
@ -85,6 +116,25 @@ sub onSelectionMade()
if LCase(m.global.sceneManager.returnData.type) = "subtitleselection"
processSubtitleSelection()
return
end if
if LCase(m.global.sceneManager.returnData.type) = "audioselection"
processAudioSelection()
return
end if
end sub
' processAudioSelection: Audio track selection handler
'
sub processAudioSelection()
selectedAudioTrack = m.global.sceneManager.returnData
if isValid(selectedAudioTrack)
if isValid(selectedAudioTrack.index)
m.view.audioIndex = selectedAudioTrack.index
end if
end if
end sub

View File

@ -8,6 +8,7 @@
<IconButton id="showVideoInfoPopup" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/videoInfo.png" height="65" width="100" />
<IconButton id="chapterList" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/numberList.png" height="65" width="100" />
<IconButton id="showSubtitleMenu" background="#070707" focusBackground="#00a4dc" padding="0" icon="pkg:/images/icons/subtitle.png" height="65" width="100" />
<IconButton id="showAudioMenu" background="#070707" focusBackground="#00a4dc" padding="27" icon="pkg:/images/icons/musicNote.png" height="65" width="100" />
</ButtonGroup>
<ButtonGroup id="videoControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="center" translation="[960,875]">

View File

@ -32,6 +32,7 @@ sub init()
m.top.observeField("state", "onState")
m.top.observeField("content", "onContentChange")
m.top.observeField("selectedSubtitle", "onSubtitleChange")
m.top.observeField("audioIndex", "onAudioIndexChange")
' Custom Caption Function
m.top.observeField("allowCaptions", "onAllowCaptionsChange")
@ -163,6 +164,12 @@ sub handleShowSubtitleMenuAction()
m.top.selectSubtitlePressed = true
end sub
' handleShowAudioMenuAction: Handles action to show audio selection menu
'
sub handleShowAudioMenuAction()
m.top.selectAudioPressed = true
end sub
' handleShowVideoInfoPopupAction: Handles action to show video info popup
'
sub handleShowVideoInfoPopupAction()
@ -204,6 +211,11 @@ sub onOSDAction()
return
end if
if action = "showaudiomenu"
handleShowAudioMenuAction()
return
end if
if action = "showvideoinfopopup"
handleShowVideoInfoPopupAction()
return
@ -262,6 +274,24 @@ sub onSubtitleChange()
m.top.control = "stop"
m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle
m.LoadMetaDataTask.selectedAudioStreamIndex = m.top.audioIndex
m.LoadMetaDataTask.itemId = m.currentItem.id
m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded")
m.LoadMetaDataTask.control = "RUN"
end sub
' Event handler for when audioIndex changes
sub onAudioIndexChange()
' Skip initial audio index setting
if m.top.position = 0 then return
' Save the current video position
m.global.queueManager.callFunc("setTopStartingPoint", int(m.top.position) * 10000000&)
m.top.control = "stop"
m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle
m.LoadMetaDataTask.selectedAudioStreamIndex = m.top.audioIndex
m.LoadMetaDataTask.itemId = m.currentItem.id
m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded")
m.LoadMetaDataTask.control = "RUN"
@ -314,6 +344,7 @@ sub onVideoContentLoaded()
m.top.container = videoContent[0].container
m.top.mediaSourceId = videoContent[0].mediaSourceId
m.top.fullSubtitleData = videoContent[0].fullSubtitleData
m.top.fullAudioData = videoContent[0].fullAudioData
m.top.audioIndex = videoContent[0].audioIndex
m.top.transcodeParams = videoContent[0].transcodeparams
m.chapters = videoContent[0].chapters

View File

@ -3,6 +3,7 @@
<interface>
<field id="backPressed" type="boolean" alwaysNotify="true" />
<field id="selectSubtitlePressed" type="boolean" alwaysNotify="true" />
<field id="selectAudioPressed" type="boolean" alwaysNotify="true" />
<field id="selectPlaybackInfoPressed" type="boolean" alwaysNotify="true" />
<field id="PlaySessionId" type="string" />
<field id="Subtitles" type="array" />
@ -22,6 +23,7 @@
<field id="videoId" type="string" />
<field id="mediaSourceId" type="string" />
<field id="fullSubtitleData" type="array" />
<field id="fullAudioData" type="array" />
<field id="audioIndex" type="integer" />
<field id="allowCaptions" type="boolean" value="false" />
</interface>

BIN
images/icons/musicNote.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB