I'm creating an autoplay video element by JS, but its play event can't always be triggered.
const video = document.createElement('video')
video.src = 'http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv'
// video.muted = true
video.loop = true
video.autoplay = true
video.addEventListener('canplay', () => {console.log('can')})
video.addEventListener('play',() => {
console.log('playing')
// setTimeout(() => {console.log(video.currentTime)}, 5000)
}, true)
Adding this line of code seems to fix the problem:
I also found this article on MDN (Mozilla), it clarified the usage of the
crossorigin
attribute on image element, but it gives useful insight for video element.