Skip to content

Commit

Permalink
Fix player state changes for shows
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Nov 11, 2024
1 parent 0657b28 commit 34a1c27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class SpotifyWebPlayer extends PureComponent<Props, State> {

this.state = {
currentDeviceId: '',
currentURI: '',
deviceId: '',
devices: [],
error: '',
Expand Down Expand Up @@ -517,6 +518,8 @@ class SpotifyWebPlayer extends PureComponent<Props, State> {
};

private handlePlayerStateChanges = async (state: Spotify.PlaybackState) => {
const { currentURI } = this.state;

try {
/* istanbul ignore else */
if (state) {
Expand All @@ -532,8 +535,9 @@ class SpotifyWebPlayer extends PureComponent<Props, State> {
const volume = (await this.player?.getVolume()) ?? 100;
let trackState = {};

if (position === 0 && current_track) {
if ((!currentURI || currentURI !== current_track.uri) && current_track) {
trackState = {
currentURI: current_track.uri,
nextTracks: next_tracks.map(convertTrack),
position: 0,
previousTracks: previous_tracks.map(convertTrack),
Expand Down
1 change: 1 addition & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface Props {

export interface State {
currentDeviceId: string;
currentURI: string;
deviceId: string;
devices: SpotifyDevice[];
error: string;
Expand Down

0 comments on commit 34a1c27

Please sign in to comment.