Skip to content

Commit

Permalink
Fixed #452. Player state is now accurate without interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
danpastori committed Apr 1, 2021
1 parent 1cf472b commit 021ebf6
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ icon*
.vscode
.sass-cache
logs/
.nova/

# AmplitudeJS Specifics
songs/*
examples/testing/*
src/PENDING
examples/songs
coverage/
ui-tests/*
ui-tests/
89 changes: 41 additions & 48 deletions dist/amplitude.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/amplitude.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/amplitude.min.js

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ import Debug from "../utilities/debug.js";
*/
import Visualizations from "../fx/visualizations.js";

/**
* Import the Config State module.
* @module utilities/configState
*/
import ConfigState from "../utilities/configState.js";

/**
* Interacts directly with native functions of the Audio element. Logic
* leading up to these methods are handled by click handlers which call
Expand Down Expand Up @@ -102,6 +108,11 @@ let Core = (function() {
}
config.audio.play();
config.audio.playbackRate = config.playback_speed;

/*
Sets the state of the player.
*/
ConfigState.setPlayerState();
}

/**
Expand All @@ -123,14 +134,20 @@ let Core = (function() {
Flag that pause button was clicked.
*/
config.paused = true;



/*
If the song is live, we disconnect the stream so we aren't
saving it to memory.
*/
if (config.active_metadata.live) {
disconnectStream();
}

/*
Sets the state of the player.
*/
ConfigState.setPlayerState();
}

/**
Expand Down Expand Up @@ -164,6 +181,11 @@ let Core = (function() {
disconnectStream();
}

/*
Sets the state of the player.
*/
ConfigState.setPlayerState();

/*
Run the stop callback
*/
Expand Down
2 changes: 0 additions & 2 deletions src/events/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ let Pause = (function() {
if (playlistAttribute != null && songIndexAttribute != null) {
handleSongInPlaylistPause(playlistAttribute, songIndexAttribute);
}

ConfigState.setPlayerState();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/events/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ let Play = (function() {
if (playlistAttribute != null && songIndexAttribute != null) {
handleSongInPlaylistPlay(playlistAttribute, songIndexAttribute);
}

ConfigState.setPlayerState();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/events/playPause.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ let PlayPause = (function() {
if (playlist != null && song != null) {
handleSongInPlaylistPlayPause(playlist, song);
}

ConfigState.setPlayerState();
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/events/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ let Stop = (function() {
Stops the active song.
*/
Core.stop();

/*
Set the state of the player.
*/
ConfigState.setPlayerState();
}
}

Expand Down
20 changes: 0 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,6 @@ let Amplitude = (function() {
*/
TimeElements.resetDurationTimes();

/*
Sets the state of the player.
*/
ConfigState.setPlayerState();
}

/**
Expand Down Expand Up @@ -802,11 +798,6 @@ let Amplitude = (function() {
*/
Core.play();

/*
Sets the state of the player.
*/
ConfigState.setPlayerState();

/*
Sync all of the play pause buttons.
*/
Expand Down Expand Up @@ -858,11 +849,6 @@ let Amplitude = (function() {
Play the song
*/
Core.play();

/*
Set the state of the player
*/
ConfigState.setPlayerState();
}

/**
Expand All @@ -876,8 +862,6 @@ let Amplitude = (function() {
*/
function play() {
Core.play();

ConfigState.setPlayerState();
}

/**
Expand All @@ -891,8 +875,6 @@ let Amplitude = (function() {
*/
function pause() {
Core.pause();

ConfigState.setPlayerState();
}

/**
Expand All @@ -905,8 +887,6 @@ let Amplitude = (function() {
*/
function stop() {
Core.stop();

ConfigState.setPlayerState();
}

/**
Expand Down

0 comments on commit 021ebf6

Please sign in to comment.