I’m working with an HTML5 webcam web script, that records, plays and uploads successfully. After recording the player instantly replays the recording on the screen.
I’m trying to see if it’s possible to only display the HTML5 native video player ‘controls’ upon replay.
Currently, when the webcam is accessed and the code begins with:
<video controls><video>
the player shows the pause button, timer, volume, full screen option. Is there a way to not show the timer? If not, is there a way to only show the ‘controls’ upon the instant replay?
Here’s my current code:
<video></video>
<button class="start" disabled>Start</button>
<button class="stop" disabled>Stop</button>
<button class="upload" disabled>Upload</button>
<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")
document.getElementById("demo").innerHTML ="recorded Successfully ..."
video.setAttribute("controls","controls")
})
// Upload the video blob as form data ............................
..................................... etc. .....................................................................
navigator
.mediaDevices
.getUserMedia({audio: true, video: true })
.then(initRecorder)
.catch(console.error)
</script>
</body>
</html>