Fixes #116. Listen to audio focus change
This commit is contained in:
parent
bf7f836465
commit
8e377d0e74
1 changed files with 7 additions and 2 deletions
|
@ -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 && (
|
||||||
|
|
Loading…
Reference in a new issue