Fixes #116. Listen to audio focus change

This commit is contained in:
Michael Tintiuc 2020-02-01 15:44:04 +02:00
parent bf7f836465
commit 8e377d0e74

View file

@ -167,7 +167,7 @@ class MediaPlayer extends React.PureComponent {
togglePlay = () => { togglePlay = () => {
this.showPlayerControls(); this.showPlayerControls();
this.setState({ paused: !this.state.paused }, this.handlePausedState); this.setState({ paused: !this.state.paused }, this.updateBackgroundMediaNotification);
}; };
handlePausedState = () => { handlePausedState = () => {
@ -188,7 +188,7 @@ class MediaPlayer extends React.PureComponent {
}; };
onEnd = () => { onEnd = () => {
this.setState({ paused: true }); this.setState({ paused: true }, this.updateBackgroundMediaNotification);
if (this.props.onPlaybackFinished) { if (this.props.onPlaybackFinished) {
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 = () => { onBuffer = () => {
if (!this.state.paused) { if (!this.state.paused) {
this.setState({ buffering: true }, () => this.manualHidePlayerControls()); this.setState({ buffering: true }, () => this.manualHidePlayerControls());
@ -469,6 +473,7 @@ class MediaPlayer extends React.PureComponent {
onEnd={this.onEnd} onEnd={this.onEnd}
onError={this.onError} onError={this.onError}
minLoadRetryCount={999} minLoadRetryCount={999}
onAudioFocusChanged={this.onFocusChanged}
/> />
{this.state.firstPlay && thumbnail && ( {this.state.firstPlay && thumbnail && (