From 8e377d0e742b1eb158630088a16211b97fdc6f69 Mon Sep 17 00:00:00 2001 From: Michael Tintiuc Date: Sat, 1 Feb 2020 15:44:04 +0200 Subject: [PATCH] Fixes #116. Listen to audio focus change --- src/component/mediaPlayer/view.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/component/mediaPlayer/view.js b/src/component/mediaPlayer/view.js index 53af706..e9e0acf 100644 --- a/src/component/mediaPlayer/view.js +++ b/src/component/mediaPlayer/view.js @@ -167,7 +167,7 @@ class MediaPlayer extends React.PureComponent { togglePlay = () => { this.showPlayerControls(); - this.setState({ paused: !this.state.paused }, this.handlePausedState); + this.setState({ paused: !this.state.paused }, this.updateBackgroundMediaNotification); }; handlePausedState = () => { @@ -188,7 +188,7 @@ class MediaPlayer extends React.PureComponent { }; onEnd = () => { - this.setState({ paused: true }); + this.setState({ paused: true }, this.updateBackgroundMediaNotification); if (this.props.onPlaybackFinished) { this.props.onPlaybackFinished(); } @@ -327,6 +327,10 @@ class MediaPlayer extends React.PureComponent { } }; + onFocusChanged = evt => { + this.setState({ paused: !(this.state.paused && evt.hasAudioFocus) }, this.updateBackgroundMediaNotification); + }; + onBuffer = () => { if (!this.state.paused) { this.setState({ buffering: true }, () => this.manualHidePlayerControls()); @@ -469,6 +473,7 @@ class MediaPlayer extends React.PureComponent { onEnd={this.onEnd} onError={this.onError} minLoadRetryCount={999} + onAudioFocusChanged={this.onFocusChanged} /> {this.state.firstPlay && thumbnail && (