From dd1f6164d971bb96295a0217d1a67d46dbfc056a Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 25 Mar 2019 06:30:33 -0700 Subject: [PATCH] Don't autoplay on next when stoppedFixes #730 --- CHANGELOG.md | 1 + js/actionCreators/media.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1bf0c93..f47447d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Bug Fixes: - Fix a bug where context menus could appear in the wrong location ([95db2d](https://github.com/captbaritone/webamp/commit/95db2d08b6b189f5b9da577d23aca44b04c462a8)) +- Fix a bug where pressing next/previous when stopped would play the track ([#740](https://github.com/captbaritone/webamp/issues/730)) ## 1.3.1 [CURRENT] diff --git a/js/actionCreators/media.ts b/js/actionCreators/media.ts index bfa13a27..b1941c1d 100644 --- a/js/actionCreators/media.ts +++ b/js/actionCreators/media.ts @@ -10,6 +10,7 @@ import { PAUSE, PLAY_TRACK, TOGGLE_TIME_MODE, + BUFFER_TRACK, } from "../actionTypes"; import { MEDIA_STATUS } from "../constants"; @@ -31,7 +32,19 @@ function playRandomTrack(): Dispatchable { } while (nextId === currentTrack && trackOrder.length > 1); // TODO: Sigh... Technically, we should detect if we are looping only repeat if we are. // I think this would require pre-computing the "random" order of a playlist. - dispatch({ type: PLAY_TRACK, id: nextId }); + dispatch(playTrack(nextId)); + }; +} + +function playTrack(id: number): Dispatchable { + return (dispatch, getState) => { + const state = getState(); + const isStopped = Selectors.getMediaStatus(state) === MEDIA_STATUS.STOPPED; + if (isStopped) { + dispatch({ type: BUFFER_TRACK, id }); + } else { + dispatch({ type: PLAY_TRACK, id }); + } }; } @@ -76,7 +89,7 @@ export function nextN(n: number): Dispatchable { if (nextTrackId == null) { return; } - dispatch({ type: PLAY_TRACK, id: nextTrackId }); + dispatch(playTrack(nextTrackId)); }; }