引用录制的视频以查看它是否正在播放 (JS)
Referencing recorded video to see if it is playing or not (JS)
所以我正在使用 Muaz Khans RecordRTC 为网站录制视频和音频。我一直在尝试编写一个脚本来查看是否正在播放录制的视频。我遇到的问题是如何引用已创建的视频。
我尝试了以下方法,但没有成功。
function vidplay() {
var video = document.getElementById("videoURL");
if (video.paused) {
//DESIRED ACTION
} else {
//DESIRED ACTION
}
}
如有任何帮助,我们将不胜感激。
请查看此演示:https://jsfiddle.net/ddxadv3y/
Simply check for video.currentTime
. It must update.
Otherwise consider video
is paused or ended.
<h1></h1>
<video controls muted style="width:20%;"></video>
<script>
var video = document.querySelector('video');
var h1 = document.querySelector('h1');
video.onloadedmetadata = function() {
if(lastTime) return;
checkForTimeChange();
};
var lastTime;
function checkForTimeChange() {
if(!lastTime) {
lastTime = video.currentTime;
}
if(lastTime == video.currentTime) {
h1.innerHTML = 'paused';
}
else {
h1.innerHTML = 'playing';
}
lastTime = video.currentTime;
setTimeout(checkForTimeChange, 500);
}
</script>
<script>
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({video: true}, function(stream) {
video.src = URL.createObjectURL(stream);
video.play();
}, function() {});
</script>
所以我正在使用 Muaz Khans RecordRTC 为网站录制视频和音频。我一直在尝试编写一个脚本来查看是否正在播放录制的视频。我遇到的问题是如何引用已创建的视频。
我尝试了以下方法,但没有成功。
function vidplay() {
var video = document.getElementById("videoURL");
if (video.paused) {
//DESIRED ACTION
} else {
//DESIRED ACTION
}
}
如有任何帮助,我们将不胜感激。
请查看此演示:https://jsfiddle.net/ddxadv3y/
Simply check for
video.currentTime
. It must update.Otherwise consider
video
is paused or ended.
<h1></h1>
<video controls muted style="width:20%;"></video>
<script>
var video = document.querySelector('video');
var h1 = document.querySelector('h1');
video.onloadedmetadata = function() {
if(lastTime) return;
checkForTimeChange();
};
var lastTime;
function checkForTimeChange() {
if(!lastTime) {
lastTime = video.currentTime;
}
if(lastTime == video.currentTime) {
h1.innerHTML = 'paused';
}
else {
h1.innerHTML = 'playing';
}
lastTime = video.currentTime;
setTimeout(checkForTimeChange, 500);
}
</script>
<script>
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({video: true}, function(stream) {
video.src = URL.createObjectURL(stream);
video.play();
}, function() {});
</script>