Make the volume control remember if muted

This commit is contained in:
Oscar Dominguez 2019-07-27 18:17:25 -03:00
parent f532ba0d8b
commit 81452a1ee6
7 changed files with 39 additions and 2 deletions

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as settings from 'constants/settings'; import * as settings from 'constants/settings';
import { doChangeVolume } from 'redux/actions/app'; import { doChangeVolume, doChangeMute } from 'redux/actions/app';
import { selectVolume } from 'redux/selectors/app'; import { selectVolume, selecetMute } from 'redux/selectors/app';
import { doPlayUri, doSetPlayingUri, savePosition } from 'redux/actions/content'; import { doPlayUri, doSetPlayingUri, savePosition } from 'redux/actions/content';
import { doClaimEligiblePurchaseRewards, makeSelectCostInfoForUri } from 'lbryinc'; import { doClaimEligiblePurchaseRewards, makeSelectCostInfoForUri } from 'lbryinc';
import { import {
@ -37,6 +37,7 @@ const select = (state, props) => ({
nextFileToPlay: makeSelectFirstRecommendedFileForUri(props.uri)(state), nextFileToPlay: makeSelectFirstRecommendedFileForUri(props.uri)(state),
nsfw: makeSelectClaimIsNsfw(props.uri)(state), nsfw: makeSelectClaimIsNsfw(props.uri)(state),
thumbnail: makeSelectThumbnailForUri(props.uri)(state), thumbnail: makeSelectThumbnailForUri(props.uri)(state),
muted: selecetMute(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
@ -45,6 +46,7 @@ const perform = dispatch => ({
changeVolume: volume => dispatch(doChangeVolume(volume)), changeVolume: volume => dispatch(doChangeVolume(volume)),
claimRewards: () => dispatch(doClaimEligiblePurchaseRewards()), claimRewards: () => dispatch(doClaimEligiblePurchaseRewards()),
savePosition: (claimId, outpoint, position) => dispatch(savePosition(claimId, outpoint, position)), savePosition: (claimId, outpoint, position) => dispatch(savePosition(claimId, outpoint, position)),
changeMute: muted => dispatch(doChangeMute(muted)),
}); });
export default connect( export default connect(

View file

@ -32,6 +32,8 @@ type Props = {
savePosition: number => void, savePosition: number => void,
changeVolume: number => void, changeVolume: number => void,
viewerContainer: { current: ElementRef<any> }, viewerContainer: { current: ElementRef<any> },
changeMute: boolean => void,
muted: boolean,
}; };
type State = { type State = {
@ -187,6 +189,8 @@ class MediaPlayer extends React.PureComponent<Props, State> {
savePosition, savePosition,
downloadPath, downloadPath,
fileName, fileName,
muted,
changeMute,
} = this.props; } = this.props;
// @if TARGET='app' // @if TARGET='app'
@ -251,9 +255,11 @@ class MediaPlayer extends React.PureComponent<Props, State> {
}); });
mediaElement.addEventListener('webkitfullscreenchange', win32FullScreenChange.bind(this)); mediaElement.addEventListener('webkitfullscreenchange', win32FullScreenChange.bind(this));
mediaElement.addEventListener('volumechange', () => { mediaElement.addEventListener('volumechange', () => {
changeMute(mediaElement.muted);
changeVolume(mediaElement.volume); changeVolume(mediaElement.volume);
}); });
mediaElement.volume = volume; mediaElement.volume = volume;
mediaElement.muted = muted;
mediaElement.addEventListener('dblclick', this.handleDoubleClick); mediaElement.addEventListener('dblclick', this.handleDoubleClick);
} }
// @endif // @endif

View file

@ -54,6 +54,8 @@ type Props = {
thumbnail: ?string, thumbnail: ?string,
isPlayableType: boolean, isPlayableType: boolean,
viewerContainer: { current: ElementRef<any> }, viewerContainer: { current: ElementRef<any> },
changeMute: boolean => void,
muted: boolean,
}; };
class FileViewer extends React.PureComponent<Props> { class FileViewer extends React.PureComponent<Props> {
@ -231,6 +233,8 @@ class FileViewer extends React.PureComponent<Props> {
viewerContainer, viewerContainer,
thumbnail, thumbnail,
nsfw, nsfw,
muted,
changeMute,
} = this.props; } = this.props;
const isPlaying = playingUri === uri; const isPlaying = playingUri === uri;
@ -290,6 +294,8 @@ class FileViewer extends React.PureComponent<Props> {
onFinishCb={this.onFileFinishCb} onFinishCb={this.onFileFinishCb}
playingUri={playingUri} playingUri={playingUri}
viewerContainer={viewerContainer} viewerContainer={viewerContainer}
muted={muted}
changeMute={changeMute}
/> />
</Suspense> </Suspense>
)} )}

View file

@ -13,6 +13,7 @@ export const DAEMON_READY = 'DAEMON_READY';
export const DAEMON_VERSION_MATCH = 'DAEMON_VERSION_MATCH'; export const DAEMON_VERSION_MATCH = 'DAEMON_VERSION_MATCH';
export const DAEMON_VERSION_MISMATCH = 'DAEMON_VERSION_MISMATCH'; export const DAEMON_VERSION_MISMATCH = 'DAEMON_VERSION_MISMATCH';
export const VOLUME_CHANGED = 'VOLUME_CHANGED'; export const VOLUME_CHANGED = 'VOLUME_CHANGED';
export const VOLUME_MUTED = 'VOLUME_MUTED';
export const ADD_COMMENT = 'ADD_COMMENT'; export const ADD_COMMENT = 'ADD_COMMENT';
export const SHOW_MODAL = 'SHOW_MODAL'; export const SHOW_MODAL = 'SHOW_MODAL';
export const HIDE_MODAL = 'HIDE_MODAL'; export const HIDE_MODAL = 'HIDE_MODAL';

View file

@ -376,6 +376,17 @@ export function doChangeVolume(volume) {
}; };
} }
export function doChangeMute(muted) {
return dispatch => {
dispatch({
type: ACTIONS.VOLUME_MUTED,
data: {
muted,
},
});
};
}
export function doClickCommentButton() { export function doClickCommentButton() {
return { return {
type: ACTIONS.ADD_COMMENT, type: ACTIONS.ADD_COMMENT,

View file

@ -51,6 +51,7 @@ const defaultState: AppState = {
hasSignature: false, hasSignature: false,
badgeNumber: 0, badgeNumber: 0,
volume: Number(sessionStorage.getItem('volume')) || 1, volume: Number(sessionStorage.getItem('volume')) || 1,
muted: false,
autoUpdateDownloaded: false, autoUpdateDownloaded: false,
autoUpdateDeclined: false, autoUpdateDeclined: false,
modalsAllowed: true, modalsAllowed: true,
@ -210,6 +211,11 @@ reducers[ACTIONS.VOLUME_CHANGED] = (state, action) =>
volume: action.data.volume, volume: action.data.volume,
}); });
reducers[ACTIONS.VOLUME_MUTED] = (state, action) =>
Object.assign({}, state, {
muted: action.data.muted,
});
reducers[ACTIONS.HISTORY_NAVIGATE] = state => reducers[ACTIONS.HISTORY_NAVIGATE] = state =>
Object.assign({}, state, { Object.assign({}, state, {
modal: undefined, modal: undefined,

View file

@ -100,6 +100,11 @@ export const selectVolume = createSelector(
state => state.volume state => state.volume
); );
export const selecetMute = createSelector(
selectState,
state => state.muted
);
export const selectUpgradeTimer = createSelector( export const selectUpgradeTimer = createSelector(
selectState, selectState,
state => state.checkUpgradeTimer state => state.checkUpgradeTimer