-1
嘿,我試圖在我的HTML5視頻源之間切換,我可以使其工作,以便它從A切換到B,但它不想從B to A.HTML5視頻使用Javascript來回更改源碼
我嘗試了很多不同的寫法,但它似乎並不奏效。 所以我希望有人能幫助我。
https://jsfiddle.net/p463qvnL/
<!DOCTYPE html>
<head>
<style>
* {
margin: 0;
padding: 0;
overflow: hidden;
}
.buttons{
position: absolute;
z-index: 9999;
bottom: 0;
}
.button {
width: 500px;
height: 200px;
background-color: rgba(255, 0, 0, 1);
border: 0;
border-color: rgba(255, 0, 0, 0);
}
.button:focus {
border: 0;
border-color: rgba(255, 0, 0, 0);
outline:0;
}
.twee {
background-color: green;
}
</style>
</head>
<body>
<div>
<div class="buttons">
<button class="button" id="pause"></button>
<button class="button twee" id="switch"></button>
</div>
<video loop autoplay id="video1" width="100%" height="100%">
<source id="video2" src="mov_bbb.mp4" type="video/mp4">
</video>
</div>
<script>
var myVideo = document.getElementById("video1");
var myVid = document.getElementById("video2");
document.getElementById("pause").addEventListener ("click", playPause);
document.getElementById("switch").addEventListener ("click", switchScreen);
function playPause(){
if (myVideo.paused){
myVideo.play();
} else {
myVideo.pause();
}
}
function switchScreen(){
if (myVid.src = "mov_bbb.mp4"){
myVid.src = "lal.mp4";
} else {
myVid.src = "mov_bbb.mp4";
}
myVideo.load();
}
</script>
</body>
</html>
是的,我知道,但如果你不使用單一=沒有關係根本不會改變從A到B. – Garneto
當然你需要單個=分配視頻url,但不是在條件 –
這似乎很奇怪,在jsfiddle它的作品,但本地它不具有相同的代碼:/ – Garneto