[英]Is there a way I can set a limitation of the videos duration using HTML5, Javascript or PHP? Sort of like snapchat and vine
I know HTML5 now has a getusermedia() where you can access their cameras. 我知道HTML5现在有一个getusermedia(),您可以在其中访问其相机。 However, is there a way where I can set a limit to how long I want the recording to go for such as 30 seconds and then save it?
但是,有没有一种方法可以设置我想要录制多长时间(例如30秒)然后保存它的限制? Or even if there's a loop hole such as having a counter or something..
或者即使有一个环形孔,例如有一个柜台或其他东西。
<script>
var video = document.querySelector("#videoElement");
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true, audio: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
document.getElementById("videoElement").pause();
}
function videoError(e) {
alert("There was an error with the video stream.\nCheck that your webcam is connected.");
}
function play()
{
var video = document.getElementById("videoElement");
var music = document.getElementById("song");
var button = document.getElementById("play");
if (video.paused) {
video.play();
music.play();
button.textContent = "Stop Recording";
} else {
video.pause();
music.pause();
button.textContent = "Continue Recording";
}
}
function show()
{
document.getElementById("record").style.display="block";
}
</script>
Just include a setInterval counter that begins when you start recording and counts up to the maximum duration, then stops the recording. 只需包含一个setInterval计数器,该计数器会在您开始记录时开始,并计数到最大持续时间,然后停止记录。 Something like:
就像是:
var time = 0;
this.audioTimer = setInterval(function () {
time += 1;
if (time >= maxDurationInSeconds) {
this.recorder.stop();
}
}, 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.