I'm developing a video player which plays a MP4 video file. This video player plays MP4 videos with no audio files included in it. I have 2 audio files which are dubbed in different languages. So far I have created two html buttons saying "English" and "Italian". The video player should switch the audio each time they have been clicked. I do not want anyone to create this code for me and give it to me. I don't know how to play a different audio and would like help. Please give me any explanations or any website url which will be able to help me.
Asked
Active
Viewed 532 times
0
-
are you needing the audio (whichever language the user selects) to be in-synch with the current video playhead? This does not sound trivial, but, part of your Audio_buttonClick event that you create will probably need to take note of the current video timestamp, and use that to advance the translation audio to the same timestamp. – bkwdesign Jan 12 '18 at 03:06
-
Try [this S.O. answer](https://stackoverflow.com/a/5698024/1520850) for some initial guidance on controlling audio playback with script – bkwdesign Jan 12 '18 at 03:08
1 Answers
2
I assume that you want to be able to switch audio while the video is running and therfore you want the audio to continue accordingly to the current time of the video. Here is a possible concept for a solution:
let vid, audioEN and audioIT be variables which stand for your video and the respectve audio files
assuming that English is chosen as the default audio, simply play vid and audioEN at the same time
when you click on the button for switching the audio files, pause the currently running audio, get its' current time and store it in some variable named T, play the other audio file and set its' current time to T. It should continue where the previous audio file left off.

zunnzunn
- 366
- 1
- 5
- 12