Oncanplaythrough vs. oncanplay

Both work.
Which should be used?

A radio stream would be considered what?
I don’t believe there is buffering involved with that.
http://hi5.1980s.fm/;

oncanplay
https://jsfiddle.net/vhgL96se/142/

The canplay event is fired when the user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.

player.oncanplay = function () {
        if (value.value !== "") {
            canPlay = true;
            playPauseIcon(true);
        }
    };

oncanplaythrough
https://jsfiddle.net/vhgL96se/144/

The canplaythrough event is fired when the user agent can play the media and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content.

player.oncanplaythrough = function () {
        if (value.value !== "") {
            canPlay = true;
            playPauseIcon(true);
        }
    };

Take a look at this, from the MDN – The difference is subtle.

canplay The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
canplaythrough The browser estimates it can play the media up to its end without stopping for content buffering.

So which do you use? In your case, it doesn’t matter. In either case, the browser thinks it has a valid media element. In the first, it may have to buffer; in the second, it shouldn’t.

But, for your purposes, I would probably use canplay – if you use canplaythrough it won’t run until a bit later on slower connections.

1 Like