How to check browser support playbackRate in source?

231 Views Asked by At

I am building a video controller capable of changing playbackRate. However, some browsers that do not support the playbackRate function would like to display the message. For example, "Not supported in this browser".

Is there a way to check if the playbackRate function is working properly in JavaScript?

Here's how I tried:

try{
    player.playbackRate = 0.95;
    // if check here : console.log(player.playbackRate) = 0.95 in not supported browser.

    if (player.playbackRate != 0.95) {
        alert('Not supported in this browser');
    }

    player.playbackRate = 1;
}
catch(e) {
    alert('Not supported in this browser');
}

However, even on browsers that do not support playbackRate, the actual playbackRate value has changed and no error or message has been output.

Is there any way I can?

I hope you can help a lot.

1

There are 1 best solutions below

1
On

You can't check if a native property exists, if you first add that property.

The way to check if a native property is supported, is generally to create a clean, new element, and see if it has that property and if the property value is what is expected

var audio = document.createElement('audio');

if ( 'playbackRate' in audio && audio.playbackRate === 1) {

    // is supported

}