New issue: CloudFlare Stream Player API 'canplay'

I think there may be a new issue with the ‘canplay’ event in the Stream Player API.
Until this morning, the following javascript worked fine as a way of changing the video in the player and playing the newly-loaded video. It’s a useful technique for adding adding a pre-roll.

player.addEventListener('play', function play_listener() {
  player.removeEventListener('play', play_listener);
  player.src = "https://iframe.videodelivery.net/" + preroll_id;
  player.addEventListener('canplay', function canplay_listener() {
  console.log("Ready to play pre-roll");
      player.removeEventListener('canplay', canplay_listener);
      player.play();
      });
});

As of this morning, although the pre-roll loads the first time the user clicks play, the user then has to click play a second time to actually play the pre-roll video. And in fact the canplay event listener and “Ready to play pre-roll” message does not fire until the second click.
Desktop Chrome, Safari, Firefox all have the same issue.
It has always worked fine until this morning.
Any ideas folks?

Workaround: Replace ‘canplay’ with ‘loadstart’ and it works.

1 Like

We made improvements to the player’s preloading logic to be more consistent with the documented behavior. If you’d like to use canplay, try adding preload=auto to the iframe URL.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.