Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the captions/audio languages when starting to cast. #134

Open
daroltidan opened this issue Jun 10, 2024 · 0 comments
Open

Changing the captions/audio languages when starting to cast. #134

daroltidan opened this issue Jun 10, 2024 · 0 comments

Comments

@daroltidan
Copy link

daroltidan commented Jun 10, 2024

When trying to cast a HLS file that already contains multiple languages for audio and captions, we can't seem to change language on the CastPlayer based on the values from the ExoPlayer.

we are using a converter from mediaItem to mediaQueueItem as follows:

val mediaItemConverted = defaultMediaItemConverter.toMediaQueueItem(item)
val mediaInfo = mediaItemConverted.media
val mediaLoadRequestData = MediaLoadRequestData.Builder()
            .setMediaInfo(mediaInfo)
            .setCurrentTime(localPlayer.currentPosition)
            .setAutoplay(localPlayer.isPlaying)
            .setActiveTrackIds(longArrayOf(selectedCaption, selectedAudio))
            .build()
        
        remoteMediaClient.load(mediaLoadRequestData)

inside the MediaConverter we have this builder:


       var selectedCaption = 0L
        val captionsTracks = captions.mapIndexed { index, format ->
            if (format.isSelected) {
                selectedCaption = index.toLong()
            }
            MediaTrack.Builder(index.toLong(), TYPE_TEXT)
                .setContentId(format.formatId)
                .setName(format.label + " test")
                .setLanguage(Locale(format.language))
                .setSubtype(MediaTrack.SUBTYPE_SUBTITLES)
                .build()
        }
        var selectedAudio = 0L
        val audioTracks = audioLanguages.mapIndexed { index, format ->
            val newIndex = captionsTracks.size + index
            if (format.isSelected) {
                selectedAudio = newIndex.toLong()
            }
            MediaTrack.Builder(newIndex.toLong(), TYPE_AUDIO)
                .setContentId(format.formatId)
                .setName(format.label + " test")
                .setLanguage(Locale(format.language))
                .build()
        }

return MediaInfo.Builder(contentId)
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setVmapAdsRequest(vastAdsRequest)
            .setContentType(localConfiguration.mimeType)
            .setContentUrl(contentUrl)
            .setMetadata(metadata)
           .setMediaTracks(listOf(captionsTracks + audioTracks))
            .setCustomData(getCustomData(mediaItem))
            .build()

initially we tried to use the setMediaTracks method (so we retrieved all the tracks from the local player and mapped them into media tracks) but the problem was that they were adding them 2 times in the list. (the ones that we added manually using setMediaTracks and the ones that are added from the HLS file)

My question here is, is there a way for us to preselect a language when casting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant