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