Skip to content

Commit

Permalink
fix: avoid play/pause button re-render by setting playing to false ea…
Browse files Browse the repository at this point in the history
…rlier
  • Loading branch information
JeffreyCA committed Jan 13, 2021
1 parent 72606c6 commit 2568f31
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,10 @@ export default class ReactJkMusicPlayer extends PureComponent {
this.setState({
currentVolumeFade: VOLUME_FADE.NONE,
currentVolumeFadeInterval: undefined,
playing: false,
updateIntervalEndVolume: undefined,
})
// It's possible that the volume level in the UI has changed since beginning of fade
// Restore volume so slider does not reset to zero
this.audio.volume = this.getListeningVolume(this.state.soundValue)
},
)
Expand All @@ -1258,9 +1259,9 @@ export default class ReactJkMusicPlayer extends PureComponent {
})
} else {
this.setState({ currentVolumeFade: VOLUME_FADE.IN })
// Start volume may not be 0 if interrupting a fade-out
const startVolume = isCurrentlyFading ? this.audio.volume : 0
const endVolume = this.getListeningVolume(this.state.soundValue)
// Always fade in from 0 to current volume
const {
fadeInterval: fadeInInterval,
updateIntervalEndVolume,
Expand All @@ -1277,6 +1278,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
currentVolumeFadeInterval: undefined,
updateIntervalEndVolume: undefined,
})
// It's possible that the volume level in the UI has changed since beginning of fade
this.audio.volume = this.getListeningVolume(this.state.soundValue)
},
)
Expand Down

0 comments on commit 2568f31

Please sign in to comment.