drzoid's avatar
Level 3

Audio track issue on video player switching back to browser lang

Is there a way to persist the selected language once selected from the Laracasts video player? In my machine it defaults to (what I believe is) the browser lang.


Currently, I've only seeing this issue with the the PHP for Beginners series, that has AI generated audio translations.

In my machine all the videos start with the audio track on the browser lang. Then I change it to English, and sometimes (not always) the video switches back the audio track to the browser lang.

So, is there a way to persist the selected language on the video player once selected?

Thanks in advance, and I apologize if this similar post was already created! Didn't find it :/

1 like
2 replies
LaryAI's avatar
Level 58

To address the issue of persisting the selected audio track language in a video player, you can implement a solution using JavaScript to store the user's language preference and apply it when the video is loaded. Here's a step-by-step approach:

  1. Store the Language Preference: Use localStorage to save the user's selected language. This way, the preference will persist across page reloads and sessions.

  2. Apply the Language Preference: When the video player is initialized, check localStorage for a saved language preference and set the audio track accordingly.

Here's a basic example of how you might implement this:

Explanation:

  • saveLanguagePreference(language): This function saves the selected language to localStorage.
  • getSavedLanguagePreference(): This function retrieves the saved language from localStorage.
  • setAudioTrack(videoElement): This function sets the audio track of the video element based on the saved language preference.
  • Event Listeners:
    • loadedmetadata: Triggered when the video metadata is loaded, allowing you to set the audio track.
    • audiochange: A custom event you might need to implement or listen for changes in the audio track selection, saving the user's choice.

This solution assumes that your video player supports audio track manipulation via JavaScript and that you have access to the audio tracks through the audioTracks property. Adjust the implementation based on the specific video player library or API you are using.

hdesoto's avatar

I'm also facing the same issue. And also in the PHP for Beginners. The auto-translated audio is fine, but I prefer listening in the original version, and I have to manually select Original Audio for each video. Please, please, can someone at Laracast fix this ? Your Lary "Quickdraw" A.I. already pointed you in the path to solve this ! ; )

1 like

Please or to participate in this conversation.