Don't break when moving outside of playlist bounds with next / previous buttons

This commit is contained in:
Lucas Verney 2016-08-11 23:46:42 +02:00
parent 7c1d7dacc3
commit 4f8f201e67
5 changed files with 51 additions and 51 deletions

View File

@ -124,20 +124,25 @@ export default createReducer(initialState, {
[PLAY_PREVIOUS_SONG]: (state) => { [PLAY_PREVIOUS_SONG]: (state) => {
const newIndex = state.get("currentIndex") - 1; const newIndex = state.get("currentIndex") - 1;
if (newIndex < 0) { if (newIndex < 0) {
// If there is an overlow on the left of the playlist, just stop // If there is an overlow on the left of the playlist, just play
// playback // first music again
// TODO: Behavior is not correct // TODO: Should seek to beginning of music
return stopPlayback(state); return state;
} else { } else {
return state.set("currentIndex", newIndex); return state.set("currentIndex", newIndex);
} }
}, },
[PLAY_NEXT_SONG]: (state) => { [PLAY_NEXT_SONG]: (state) => {
const newIndex = state.get("currentIndex") + 1; const newIndex = state.get("currentIndex") + 1;
if (newIndex > state.get("playlist").size) { if (newIndex >= state.get("playlist").size) {
// If there is an overflow, just stop playback // If there is an overflow
// TODO: Behavior is not correct if (state.get("isRepeat")) {
return stopPlayback(state); // TODO: Handle repeat
return state;
} else {
// Just stop playback
return state.set("isPlaying", false);
}
} else { } else {
// Else, play next item // Else, play next item
return state.set("currentIndex", newIndex); return state.set("currentIndex", newIndex);

View File

@ -75,21 +75,16 @@ class WebPlayer extends Component {
startPlaying(props) { startPlaying(props) {
if (props.isPlaying && props.currentSong) { if (props.isPlaying && props.currentSong) {
// If it should be playing any song // If it should be playing any song
if (!this.howl) { // Build a new Howler object with current song to play
// Build a new Howler object with current song to play const url = props.currentSong.get("url");
const url = props.currentSong.get("url"); this.howl = new Howl({
this.howl = new Howl({ src: [url],
src: [url], html5: true, // Use HTML5 by default to allow streaming
html5: true, // Use HTML5 by default to allow streaming mute: props.isMute,
mute: props.isMute, volume: props.volume / 100, // Set current volume
volume: props.volume / 100, // Set current volume autoplay: false, // No autoplay, we handle it manually
autoplay: false, // No autoplay, we handle it manually onend: () => props.actions.playNextSong(), // Play next song at the end
onend: () => props.actions.playNextSong(), // Play next song at the end });
});
} else {
// Else, something is playing
// TODO If it is not the expected song, change it
}
// Start playing // Start playing
this.howl.play(); this.howl.play();
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long