souporserious / react-media-player

React audio and video player.
https://souporserious.github.io/react-media-player/
ISC License
470 stars 100 forks source link

Support Rendering with Audio Context Suspended #55

Open epihel opened 5 years ago

epihel commented 5 years ago

As of version M71 (December 2018), Chrome has disabled autoplaying sound and video (https://goo.gl/7K7WLu). This line:

import { controls, Media, Player } from 'react-media-player';

will trigger the warning The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

This line in render:

<Player useAudioObject />

will throw the Error:

TypeError: Cannot set property 'oncanplay' of undefined
    at HTML5.js:229
    at Array.forEach (<anonymous>)
    at ProxyComponent._bindAudioObjectEvents (HTML5.js:228)
    at ProxyComponent._bindAudioObjectEvents (react-hot-loader.development.js:693)
    at ProxyComponent.componentDidUpdate (HTML5.js:132)
    at ProxyComponent.componentDidUpdate (react-hot-loader.development.js:683)
    at commitLifeCycles (react-dom.development.js:16242)
    at commitAllLifeCycles (react-dom.development.js:17592)
    at HTMLUnknownElement.callCallback (react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:199)

Note that removing useAudioObject, as in:

<Player />

will not throw the Error.