How can I change the Audio Source of a Video in HTML?

烂漫一生 提交于 2020-02-06 08:20:06

问题


I want to change the audio track of a video that I am playing in html. This is my sample code.

<!DOCTYPE html>
<html>
<head>
    <title>Video</title>
</head>
<body>
<video controls playsinline autoplay muted loop>
  <source src="video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>

Inside the same folder, I have an audio.mp3. I don't want to mute this video and append a hidden player and play both separately, basically I want to change the audio source. If anyone has done it, please guide me or let me know in which direction should I search? Thanks.


回答1:


I don't think that you can change the source of the audio only in your video tag.

So yes, the hack of having the video muted and a hidden audio would probably be the simplest solution.

The best one would certainly be to rebuild your video, server-side, using the audio source you want for that video.

I'd use ffmpeg for that : https://superuser.com/questions/1137612/ffmpeg-replace-audio-in-video



来源:https://stackoverflow.com/questions/59103287/how-can-i-change-the-audio-source-of-a-video-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!