Jump to content

Help with limiting the recording time


Chrisj

Recommended Posts

This record-video script works successfully. How can I limit the recording time once the ‘Start’ button is selected?

I'm trying to add this:

<script>
var recordTimeout;

function stopClickHandler(evt) {
    clearTimeout(recordTimeout);
}

function startClickHandler(evt) {
    stopClickHandler();
    recordTimeout = setTimeout(recLimit,3000);
}

var recLimit;

  function recLimit() {
  stopvideo.addEventListener('click', ())
.trigger( event );
  }

document.querySelector(".start").addEventListener(startClickHandler);
document.querySelector(".stop").addEventListener(stopClickHandler);
</script>

but I think the 'function recLimit' section needs help. Any guidance/solutions will be appreciated.

Here's most of the recording script:

<script>
            const video = document.querySelector('video')
            const startvideo = document.querySelector('.start')
            const stopvideo = document.querySelector('.stop')
            const upload = document.querySelector('.upload')
            const initRecorder = stream => {
            const recorder = new MediaRecorder(stream)
            let blob
              video.srcObject = stream
              startvideo.removeAttribute('disabled')
              video.addEventListener('loadedmetadata', () => {
              video.play()
              })
              recorder.addEventListener('dataavailable', ({ data }) => {
              video.srcObject = null
              video.src = URL.createObjectURL(data)
              // Create a blob from the data for upload
              blob = new Blob([data], { type: 'video/webm' })
              })

              startvideo.addEventListener('click', () => {
              stopvideo.removeAttribute('disabled')

              show()
              reset()
              start()
              recorder.start()
	 // Get the video element with id="myVideo"
	document.getElementsByTagName("span")[0].removeAttribute("class")
	document.getElementsByTagName("span")[0].setAttribute("class", "colorred")
	//document.getElementById("demo").innerHTML ="Recording...."
			})

	stopvideo.addEventListener('click', () => {
              upload.removeAttribute('disabled')
              recorder.stop()
              stop()
		document.getElementsByTagName("span")[0].removeAttribute("class")
		document.getElementsByTagName("span")[0].setAttribute("class", "colorgreen")
				
              video.setAttribute("controls","controls")
						})

		// Upload the video blob as form data ............................
              upload.addEventListener('click', () => {
              uploadBlob(blob)
            })
          }

           ///////////////////////////////////////////////////
		  	//Reset the Camera
		  	function resetCamera(){
		  	location.reload();
		  	 }
/////////////////////////////////////////////////////////

		 //   uploading functionality ....

 

 

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.