I am developing a web application that embeds YouTube videos using the IFrame Player API. Many of the videos I need to embed offer multiple audio tracks (e.g., original language and AI-dubbed versions).
My goal is to either:
Programmatically set a specific default audio track language (e.g., always English) for the embedded video when it loads.
Programmatically detect which audio track is currently playing (e.g., to display this information to the user or trigger further actions).
What I've tried and observed:
I am initializing the player using new YT.Player(), passing parameters in the playerVars object.
I've tried setting the hl (host language) parameter in playerVars (e.g., 'en'). This correctly changes the player's UI language, but it does not influence the default audio track selection.
I've also used cc_load_policy and cc_lang_pref for captions, which work as expected for subtitles, but these are separate from audio tracks.
I've reviewed the official YouTube IFrame Player API documentation thoroughly and cannot find any methods related to audio track selection or detection (setAudioTrack, getAudioTrack, etc.).
On the native YouTube website, users can manually select an audio track from the settings cog if multiple options exist for a video. YouTube also sometimes defaults to an auto-dubbed version based on user or browser settings.
My Problem:
The lack of API control over audio tracks presents a significant challenge for providing a consistent and user-friendly experience, especially when dealing with videos that have AI-generated dubs that might not always be preferred by the user over the original audio. Viewers currently have to manually navigate to the settings cog to change the audio track, which is not ideal.