From a0fb77baa3373f05a285c19d22ffaf65057c4b97 Mon Sep 17 00:00:00 2001 From: William Syms Date: Wed, 3 Oct 2018 18:49:18 -0400 Subject: [PATCH] Handle play promise --- src/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index dd8e302..5da5cdb 100755 --- a/src/index.js +++ b/src/index.js @@ -108,7 +108,16 @@ export default class Sound extends React.Component { if (this.props.playStatus === playStatuses.PLAYING) { if (sound.playState === 0) { - sound.play(); + var playPromise = sound.play(); + + if (playPromise !== undefined) { + playPromise.then(_ => { + // Automatic playback started! + }) + .catch(error => { + // Auto-play was prevented + }); + } } if (sound.paused) {