From 82252e69853266edf8eeedd6fb0a349621bf2429 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 31 Jul 2018 09:29:28 -0400 Subject: [PATCH] remove media.paused; catch file open pause from change of content.playingUri --- .../component/fileDownloadLink/index.js | 5 ++-- .../component/fileDownloadLink/view.jsx | 7 +++-- src/renderer/component/fileViewer/index.js | 5 ---- .../component/fileViewer/internal/player.jsx | 9 +++---- src/renderer/component/fileViewer/view.jsx | 11 ++------ src/renderer/constants/action_types.js | 7 ----- src/renderer/page/file/index.js | 7 ++--- src/renderer/redux/actions/app.js | 7 ++--- src/renderer/redux/actions/media.js | 13 --------- src/renderer/redux/reducers/media.js | 27 ------------------- src/renderer/redux/selectors/media.js | 5 ---- src/renderer/store.js | 2 -- 12 files changed, 17 insertions(+), 88 deletions(-) delete mode 100644 src/renderer/redux/actions/media.js delete mode 100644 src/renderer/redux/reducers/media.js delete mode 100644 src/renderer/redux/selectors/media.js diff --git a/src/renderer/component/fileDownloadLink/index.js b/src/renderer/component/fileDownloadLink/index.js index 23ed6b3f7..6d4334e01 100644 --- a/src/renderer/component/fileDownloadLink/index.js +++ b/src/renderer/component/fileDownloadLink/index.js @@ -7,8 +7,7 @@ import { makeSelectClaimForUri, } from 'lbry-redux'; import { doOpenFileInShell } from 'redux/actions/file'; -import { doPurchaseUri, doStartDownload } from 'redux/actions/content'; -import { doPause } from 'redux/actions/media'; +import { doPurchaseUri, doStartDownload, doSetPlayingUri } from 'redux/actions/content'; import FileDownloadLink from './view'; const select = (state, props) => ({ @@ -24,7 +23,7 @@ const perform = dispatch => ({ openInShell: path => dispatch(doOpenFileInShell(path)), purchaseUri: uri => dispatch(doPurchaseUri(uri)), restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)), - doPause: () => dispatch(doPause()), + pause: () => dispatch(doSetPlayingUri(null)), }); export default connect( diff --git a/src/renderer/component/fileDownloadLink/view.jsx b/src/renderer/component/fileDownloadLink/view.jsx index bcb352eb2..1ffe15690 100644 --- a/src/renderer/component/fileDownloadLink/view.jsx +++ b/src/renderer/component/fileDownloadLink/view.jsx @@ -22,7 +22,7 @@ type Props = { restartDownload: (string, number) => void, openInShell: string => void, purchaseUri: string => void, - doPause: () => void, + pause: () => void, }; class FileDownloadLink extends React.PureComponent { @@ -50,14 +50,13 @@ class FileDownloadLink extends React.PureComponent { purchaseUri, costInfo, loading, - doPause, - claim, + pause, } = this.props; const openFile = () => { if (fileInfo) { openInShell(fileInfo.download_path); - doPause(); + pause(); } }; diff --git a/src/renderer/component/fileViewer/index.js b/src/renderer/component/fileViewer/index.js index e34786474..005dc45f5 100644 --- a/src/renderer/component/fileViewer/index.js +++ b/src/renderer/component/fileViewer/index.js @@ -3,7 +3,6 @@ import * as settings from 'constants/settings'; import { doChangeVolume } from 'redux/actions/app'; import { selectVolume } from 'redux/selectors/app'; import { doPlayUri, doSetPlayingUri, savePosition } from 'redux/actions/content'; -import { doPlay, doPause } from 'redux/actions/media'; import { makeSelectMetadataForUri, makeSelectContentTypeForUri, @@ -15,7 +14,6 @@ import { selectSearchBarFocused, } from 'lbry-redux'; import { makeSelectClientSetting, selectShowNsfw } from 'redux/selectors/settings'; -import { selectMediaPaused } from 'redux/selectors/media'; import { selectPlayingUri, makeSelectContentPositionForUri } from 'redux/selectors/content'; import { selectFileInfoErrors } from 'redux/selectors/file_info'; import FileViewer from './view'; @@ -31,7 +29,6 @@ const select = (state, props) => ({ playingUri: selectPlayingUri(state), contentType: makeSelectContentTypeForUri(props.uri)(state), volume: selectVolume(state), - mediaPaused: selectMediaPaused(state), playbackPosition: makeSelectContentPositionForUri(props.uri)(state), autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), searchBarFocused: selectSearchBarFocused(state), @@ -42,8 +39,6 @@ const perform = dispatch => ({ play: uri => dispatch(doPlayUri(uri)), cancelPlay: () => dispatch(doSetPlayingUri(null)), changeVolume: volume => dispatch(doChangeVolume(volume)), - doPlay: () => dispatch(doPlay()), - doPause: () => dispatch(doPause()), savePosition: (claimId, outpoint, position) => dispatch(savePosition(claimId, outpoint, position)), }); diff --git a/src/renderer/component/fileViewer/internal/player.jsx b/src/renderer/component/fileViewer/internal/player.jsx index 6f7782c5f..50ba340aa 100644 --- a/src/renderer/component/fileViewer/internal/player.jsx +++ b/src/renderer/component/fileViewer/internal/player.jsx @@ -27,9 +27,11 @@ class MediaPlayer extends React.PureComponent { this.toggleFullScreenVideo = this.toggleFullScreen.bind(this); } - componentWillReceiveProps(nextProps) { + componentDidUpdate(nextProps) { const el = this.refs.media.children[0]; - if (!this.props.paused && nextProps.paused && !el.paused) el.pause(); + if (this.props.playingUri && !nextProps.playingUri && !el.paused) { + el.pause(); + } } componentDidMount() { @@ -87,8 +89,6 @@ class MediaPlayer extends React.PureComponent { const mediaElement = this.media.children[0]; if (mediaElement) { mediaElement.currentTime = position || 0; - mediaElement.addEventListener('play', () => this.props.doPlay()); - mediaElement.addEventListener('pause', () => this.props.doPause()); mediaElement.addEventListener('timeupdate', () => this.props.savePosition( claim.claim_id, @@ -140,7 +140,6 @@ class MediaPlayer extends React.PureComponent { if (mediaElement) { mediaElement.removeEventListener('click', this.togglePlayListener); } - this.props.doPause(); } toggleFullScreen(event) { diff --git a/src/renderer/component/fileViewer/view.jsx b/src/renderer/component/fileViewer/view.jsx index e213092dd..7fa36ffee 100644 --- a/src/renderer/component/fileViewer/view.jsx +++ b/src/renderer/component/fileViewer/view.jsx @@ -34,10 +34,7 @@ type Props = { volume: number, claim: Claim, uri: string, - doPlay: () => void, - doPause: () => void, savePosition: (string, string, number) => void, - mediaPaused: boolean, playbackPosition: ?number, className: ?string, obscureNsfw: boolean, @@ -202,10 +199,7 @@ class FileViewer extends React.PureComponent { volume, claim, uri, - doPlay, - doPause, savePosition, - mediaPaused, playbackPosition, className, obscureNsfw, @@ -237,6 +231,7 @@ class FileViewer extends React.PureComponent {
{isPlaying && (
+

hai

{!isReadyToPlay ? (
@@ -251,13 +246,11 @@ class FileViewer extends React.PureComponent { downloadCompleted={fileInfo.completed} changeVolume={changeVolume} volume={volume} - doPlay={doPlay} - doPause={doPause} savePosition={savePosition} claim={claim} uri={uri} - paused={mediaPaused} position={playbackPosition} + playingUri={playingUri} /> )}
diff --git a/src/renderer/constants/action_types.js b/src/renderer/constants/action_types.js index 9596eed3e..7cace66ca 100644 --- a/src/renderer/constants/action_types.js +++ b/src/renderer/constants/action_types.js @@ -182,13 +182,6 @@ export const FETCH_SUBSCRIPTIONS_START = 'FETCH_SUBSCRIPTIONS_START'; export const FETCH_SUBSCRIPTIONS_FAIL = 'FETCH_SUBSCRIPTIONS_FAIL'; export const FETCH_SUBSCRIPTIONS_SUCCESS = 'FETCH_SUBSCRIPTIONS_SUCCESS'; -// Video controls -export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE'; - -// Media controls -export const MEDIA_PLAY = 'MEDIA_PLAY'; -export const MEDIA_PAUSE = 'MEDIA_PAUSE'; - // Publishing export const CLEAR_PUBLISH = 'CLEAR_PUBLISH'; export const UPDATE_PUBLISH_FORM = 'UPDATE_PUBLISH_FORM'; diff --git a/src/renderer/page/file/index.js b/src/renderer/page/file/index.js index 99a89e4fd..9799fa4b5 100644 --- a/src/renderer/page/file/index.js +++ b/src/renderer/page/file/index.js @@ -17,7 +17,6 @@ import { } from 'lbry-redux'; import { selectShowNsfw, makeSelectClientSetting } from 'redux/selectors/settings'; import { selectSubscriptions } from 'redux/selectors/subscriptions'; -import { selectMediaPaused } from 'redux/selectors/media'; import { doPrepareEdit } from 'redux/actions/publish'; import FilePage from './view'; @@ -31,7 +30,6 @@ const select = (state, props) => ({ rewardedContentClaimIds: selectRewardContentClaimIds(state, props), subscriptions: selectSubscriptions(state), playingUri: selectPlayingUri(state), - isPaused: selectMediaPaused(state), claimIsMine: makeSelectClaimIsMine(props.uri)(state), autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), }); @@ -46,4 +44,7 @@ const perform = dispatch => ({ setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), }); -export default connect(select, perform)(FilePage); +export default connect( + select, + perform +)(FilePage); diff --git a/src/renderer/redux/actions/app.js b/src/renderer/redux/actions/app.js index 7b6e2cc31..1c8337d01 100644 --- a/src/renderer/redux/actions/app.js +++ b/src/renderer/redux/actions/app.js @@ -16,8 +16,8 @@ import Native from 'native'; import { doFetchRewardedContent } from 'redux/actions/content'; import { doFetchDaemonSettings } from 'redux/actions/settings'; import { doAuthNavigate } from 'redux/actions/navigation'; -import { doPause } from 'redux/actions/media'; -import { doCheckSubscriptionsInit } from 'redux/actions/subscriptions'; +import { doAuthenticate } from 'redux/actions/user'; +import { doCheckSubscriptions } from 'redux/actions/subscriptions'; import { selectIsUpgradeSkipped, selectUpdateUrl, @@ -109,9 +109,6 @@ export function doDownloadUpgradeRequested() { return (dispatch, getState) => { const state = getState(); - // Pause video if needed - dispatch(doPause()); - const autoUpdateDeclined = selectAutoUpdateDeclined(state); if (['win32', 'darwin'].includes(process.platform)) { diff --git a/src/renderer/redux/actions/media.js b/src/renderer/redux/actions/media.js deleted file mode 100644 index 99f297c5d..000000000 --- a/src/renderer/redux/actions/media.js +++ /dev/null @@ -1,13 +0,0 @@ -// @flow -import * as actions from 'constants/action_types'; -import type { Dispatch } from 'redux/reducers/media'; - -export const doPlay = () => (dispatch: Dispatch) => - dispatch({ - type: actions.MEDIA_PLAY, - }); - -export const doPause = () => (dispatch: Dispatch) => - dispatch({ - type: actions.MEDIA_PAUSE, - }); diff --git a/src/renderer/redux/reducers/media.js b/src/renderer/redux/reducers/media.js deleted file mode 100644 index 981820a27..000000000 --- a/src/renderer/redux/reducers/media.js +++ /dev/null @@ -1,27 +0,0 @@ -// @flow -import * as actions from 'constants/action_types'; -import { handleActions } from 'util/redux-utils'; - -export type MediaState = { - paused: Boolean, -}; - -export type Action = any; -export type Dispatch = (action: Action) => any; - -const defaultState = { paused: true, positions: {} }; - -export default handleActions( - { - [actions.MEDIA_PLAY]: (state: MediaState, action: Action) => ({ - ...state, - paused: false, - }), - - [actions.MEDIA_PAUSE]: (state: MediaState, action: Action) => ({ - ...state, - paused: true, - }), - }, - defaultState -); diff --git a/src/renderer/redux/selectors/media.js b/src/renderer/redux/selectors/media.js deleted file mode 100644 index a0518307f..000000000 --- a/src/renderer/redux/selectors/media.js +++ /dev/null @@ -1,5 +0,0 @@ -import { createSelector } from 'reselect'; - -const selectState = state => state.media || {}; - -export const selectMediaPaused = createSelector(selectState, state => state.paused); diff --git a/src/renderer/store.js b/src/renderer/store.js index 690387ffe..ba2f25b86 100644 --- a/src/renderer/store.js +++ b/src/renderer/store.js @@ -17,7 +17,6 @@ import settingsReducer from 'redux/reducers/settings'; import userReducer from 'redux/reducers/user'; import shapeShiftReducer from 'redux/reducers/shape_shift'; import subscriptionsReducer from 'redux/reducers/subscriptions'; -import mediaReducer from 'redux/reducers/media'; import publishReducer from 'redux/reducers/publish'; import { persistStore, autoRehydrate } from 'redux-persist'; import createCompressor from 'redux-persist-transform-compress'; @@ -69,7 +68,6 @@ const reducers = combineReducers({ user: userReducer, shapeShift: shapeShiftReducer, subscriptions: subscriptionsReducer, - media: mediaReducer, publish: publishReducer, notifications: notificationsReducer, blacklist: blacklistReducer,