I’d like to use something like can-autoplay to mute an autoplay video if necessary.
I’m initializing the Cloudflare player via javascript, so I was looking for some kind of initialization/player-ready hook where I could decide what to do then play() manually. Any tips?
Can you clarify? Stream seems to just pass the autoplay attribute straight through to the video tag.
Either way my issue is that the simple autoplay property doesn’t work for my use case and I’m looking for a way to hook into Stream’s initialization process so I can do my own autoplay logic
Here’s the full durationchanged hook code, since I might get rid of my repository:
<script>
// Hey Jamie! - You can listen to the "durationchange" event
// from us which we fire when we learn about the duration of
// the video for the first time.
//
// I've tried this on FF and Safari both on autoplay allowed
// and autoplay banned modes. Chrome approaches this in a
// bit more smart way with the Media Engagement Index at
// chrome://media-engagement.
//
// Using durationchange like this is undocumented and a mini hack.
// We could fire off another event faster than this one or consider
// consider your proposed behavior as default behavior for autoplay.
// We have decided to leave the autoplay decisions to the
// user agent and keep our player api consistent with the HTML5
// <video> element for now.
// You can find the documented events and attributes here:
// https://developers.cloudflare.com/stream/video-playback/player-api/#events
//
let stream = document.getElementsByTagName("stream")[0];
let eventFired = false
stream.addEventListener("durationchange", function(){
if (eventFired) { return }
eventFired = true
let video = player.querySelector('video');
video.play();
});
});
</script>