Fix playing music on Chrome
This commit is contained in:
parent
9ffc145834
commit
3ba6f08986
|
@ -67,6 +67,13 @@ class MusicPlayer extends React.Component<MusicPlayerProps, State> {
|
|||
}
|
||||
|
||||
if (this.props.playing) {
|
||||
// Chrome is super awkward about AudioContext, and won't
|
||||
// even allow creating one without complaining about
|
||||
// wanting user input, so we need to resume the context
|
||||
// before we can actually play.
|
||||
//
|
||||
// Luckily, this has no adverse effects on Firefox.
|
||||
context.resume().then(() => {
|
||||
source
|
||||
.play()
|
||||
.then(() => {
|
||||
|
@ -75,6 +82,7 @@ class MusicPlayer extends React.Component<MusicPlayerProps, State> {
|
|||
.catch((error) => {
|
||||
console.error(`Could not play audio: ${error}`);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
source.pause();
|
||||
}
|
||||
|
|
Reference in a new issue