如何在HTML中用视频外部播放音频?

编程入门 行业动态 更新时间:2024-10-05 09:31:26
本文介绍了如何在HTML中用视频外部播放音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我该如何在外部将音频与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&amp;id=1MQMkk7BUzx5K4vYt5s5GXUXTiVLAd20q" type="video/ogg" /> <source src="drive.google/uc?export=download&amp;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&amp;id=1MQMkk7BUzx5K4vYt5s5GXUXTiVLAd20q" type="video/ogg" /> <source src="drive.google/uc?export=download&amp;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&amp;id=1r9HFQeSUjE2InM7LOuNx7qaMzaVkQNfF" type="video/mp4" /> <audio id="audio" controls> <source src="drive.google/uc?export=download&amp;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中用视频外部播放音频?

本文发布于:2023-11-28 03:17:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中用   音频   如何在   视频   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!