diff --git a/js/actionCreators.js b/js/actionCreators.js index a771c452..9f533095 100644 --- a/js/actionCreators.js +++ b/js/actionCreators.js @@ -8,6 +8,7 @@ import { LOAD_AUDIO_FILE, LOAD_AUDIO_URL, OPEN_FILE_DIALOG, + SEEK_TO_PERCENT_COMPLETE, SET_BALANCE, SET_BAND_VALUE, SET_SKIN_DATA, @@ -36,6 +37,20 @@ export function stop() { return {type: STOP}; } +export function seekForward(seconds) { + return function(dispatch, getState) { + const {media} = getState(); + const {timeElapsed, length} = media; + const newTimeElapsed = timeElapsed + seconds; + const newPercentComplete = newTimeElapsed / length; + dispatch({type: SEEK_TO_PERCENT_COMPLETE, percent: newPercentComplete}); + }; +} + +export function seekBackward(seconds) { + return seekForward(-seconds); +} + export function close() { return (dispatch) => { dispatch({type: STOP}); diff --git a/js/hotkeys.js b/js/hotkeys.js index 4588f066..9a5e3f19 100644 --- a/js/hotkeys.js +++ b/js/hotkeys.js @@ -5,7 +5,9 @@ import { adjustVolume, toggleRepeat, toggleShuffle, - openFileDialog + openFileDialog, + seekForward, + seekBackward, } from './actionCreators'; import { @@ -41,19 +43,20 @@ export default function(winamp, {dispatch}) { } else { switch (e.keyCode) { case 37: // left arrow - winamp.seekForwardBy(-5); + dispatch(seekBackward(5)); + //winamp.seekForwardBy(-5); break; case 38: // up arrow dispatch(adjustVolume(1)); break; case 39: // right arrow - winamp.seekForwardBy(5); + dispatch(seekForward(5)); break; case 40: // down arrow dispatch(adjustVolume(-1)); break; case 66: // B - winamp.next(); + // Next break; case 67: // C dispatch(pause()); @@ -74,37 +77,37 @@ export default function(winamp, {dispatch}) { dispatch(play()); break; case 90: // Z - winamp.previous(); + // Previous break; case 96: // numpad 0 dispatch(openFileDialog(winamp.fileInput)); break; case 97: // numpad 1 - winamp.previous(10); + // Previous (10 tracks) break; case 98: // numpad 2 dispatch(adjustVolume(-1)); break; case 99: // numpad 3 - winamp.next(10); + // Next (10 tracks) break; case 100: // numpad 4 - winamp.previous(); + // Previous break; case 101: // numpad 5 dispatch(play()); break; case 102: // numpad 6 - winamp.next(); + // Next break; case 103: // numpad 7 - winamp.seekForwardBy(-5); + dispatch(seekBackward(5)); break; case 104: // numpad 8 dispatch(adjustVolume(1)); break; case 105: // numpad 9 - winamp.seekForwardBy(5); + dispatch(seekForward(5)); break; } } @@ -112,6 +115,7 @@ export default function(winamp, {dispatch}) { // Easter Egg keylog.push(e.keyCode); keylog = keylog.slice(-10); + // TODO: Find a less stupid way to compare arrays. if (keylog.toString() === trigger.toString()) { dispatch({type: TOGGLE_LLAMA_MODE}); }