From 253f29218acac6a2f4b1896d42f5f2645dcaa889 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Thu, 14 Dec 2017 17:21:35 -0800 Subject: [PATCH] Make default volume match actual Winamp's volume upon install. --- js/mediaMiddleware.js | 8 ++++++++ js/reducers/index.js | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/js/mediaMiddleware.js b/js/mediaMiddleware.js index 181e7026..f6eb4e9e 100644 --- a/js/mediaMiddleware.js +++ b/js/mediaMiddleware.js @@ -21,6 +21,13 @@ import { next as nextTrack } from "./actionCreators"; import { getCurrentTrackId } from "./selectors"; export default media => store => { + const { media: { volume, balance } } = store.getState(); + + // Ensure the default state is the canonical value. + media.setVolume(volume); + media.setBalance(balance); + // TODO: Ensure other values like bands and preamp are in sync + media.addEventListener("timeupdate", () => { store.dispatch({ type: UPDATE_TIME_ELAPSED, @@ -57,6 +64,7 @@ export default media => store => { }); return next => action => { + // TODO: Consider doing this after the action, and using the state as the source of truth. switch (action.type) { case PLAY: media.play(); diff --git a/js/reducers/index.js b/js/reducers/index.js index 68cb8054..46ed892b 100644 --- a/js/reducers/index.js +++ b/js/reducers/index.js @@ -204,7 +204,10 @@ const media = (state, action) => { length: null, // Consider renaming to "duration" kbps: null, khz: null, - volume: 50, + // The winamp ini file declares the default volume as "200". + // The UI seems to show a default volume near 78, which would + // math with the default value being 200 out of 255. + volume: Math.round(200 / 255 * 100), balance: 0, channels: null, shuffle: false,