我该如何在外部将音频与html中的视频一起播放?
How can I play audio externally with video in html?
例如:
<video controls="controls" style="margin-bottom:20px;width:590px"> <source src="drive.google/uc?export=download&id=1MQMkk7BUzx5K4vYt5s5GXUXTiVLAd20q" type="video/ogg" /> <source src="drive.google/uc?export=download&id=1r9HFQeSUjE2InM7LOuNx7qaMzaVkQNfF" type="video/mp4" /> </video>.ogg文件是音频文件,.mp4是视频文件 当用户单击播放按钮时,我希望他们观看视频,但音频来自.ogg文件
The .ogg file here is an audio file and the .mp4 is a video file When users click on the play button I want them to see the video but for the audio to come from the .ogg file
注意:.mp4文件具有自己的音频,但我不希望用户听该音频,我希望他们听.ogg文件中的外部音频
NOTE: .mp4 file have its own audio but I don't want users to listen to that audio I want them to listen to the external audio from .ogg file
推荐答案那是您的代码:
<video controls="controls" style="margin-bottom:20px;width:590px"> <source src="drive.google/uc?export=download&id=1MQMkk7BUzx5K4vYt5s5GXUXTiVLAd20q" type="video/ogg" /> <source src="drive.google/uc?export=download&id=1r9HFQeSUjE2InM7LOuNx7qaMzaVkQNfF" type="video/mp4" /> </video>提供视频和音频标签的"id"属性
Give Your Video and Audio Tags "id" attribute
<video id="video" controls muted> <source src="drive.google/uc?export=download&id=1r9HFQeSUjE2InM7LOuNx7qaMzaVkQNfF" type="video/mp4" /> <audio id="audio" controls> <source src="drive.google/uc?export=download&id=1MQMkk7BUzx5K4vYt5s5GXUXTiVLAd20q" type="video/ogg" /> </audio> </video>并编写脚本
<script> var v = document.getElementById("myvideo"); var a = document.getElementById("myaudio"); v.onplay = function() { a.play(); } v.onpause = function() { v.pause(); } </script>仅此而已. 实际上,这里发生的是,当播放视频时,将同时播放音频文件,并且每当暂停视频时,也会暂停音频. 同时,您的视频将始终处于静音状态.
That's all. Actually, What's happening here is that when your video will be played than your audio file will be played simultaneously and whenever your video will be paused than your audio will be paused also. At the same time, your video will be muted all the time.
更多推荐
如何在HTML中用视频外部播放音频?
发布评论