视频或音频标签可以具有“ preload = none”属性。但这意味着重新加载页面时不会预加载媒体。但是,当动态更改媒体的src时,页面不会重新加载,因此它不起作用。我不确定在这种情况下如何防止预加载:
<html>
<body>
<button onclick="myFunction()" type="button">Change Video</button><br>
<video id="myVideo" controls preload="auto">
<source id="mp4_src" src="mov_bbb.mp4" type="video/mp4">
<source id="ogg_src" src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
var vid = document.getElementById("myVideo");
function myFunction() {
isSupp = vid.canPlayType("video/mp4");
if (isSupp == "") {
vid.src = "movie.ogg";
} else {
vid.src = "movie.mp4";
}
vid.load();
}
</script>
</body>
</html>