Commit 8e377d0e authored by Michael Tintiuc's avatar Michael Tintiuc
Browse files

Fixes #116. Listen to audio focus change

parent bf7f8364
......@@ -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 && (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment