store position by outpoint
This commit is contained in:
parent
ecd2207314
commit
345badb049
5 changed files with 28 additions and 17 deletions
|
@ -35,7 +35,8 @@ class VideoPlayer extends React.PureComponent {
|
|||
changeVolume,
|
||||
volume,
|
||||
position,
|
||||
id,
|
||||
claim,
|
||||
uri,
|
||||
} = this.props;
|
||||
|
||||
const loadedMetadata = e => {
|
||||
|
@ -70,11 +71,11 @@ class VideoPlayer extends React.PureComponent {
|
|||
document.addEventListener("keydown", this.togglePlayListener);
|
||||
const mediaElement = this.refs.media.children[0];
|
||||
if (mediaElement) {
|
||||
mediaElement.currentTime = position;
|
||||
mediaElement.currentTime = position || 0;
|
||||
mediaElement.addEventListener("play", () => this.props.doPlay());
|
||||
mediaElement.addEventListener("pause", () => this.props.doPause());
|
||||
mediaElement.addEventListener("timeupdate", () =>
|
||||
this.props.savePosition(id, mediaElement.currentTime)
|
||||
this.props.savePosition(claim.claim_id, mediaElement.currentTime)
|
||||
);
|
||||
mediaElement.addEventListener("click", this.togglePlayListener);
|
||||
mediaElement.addEventListener(
|
||||
|
|
|
@ -62,6 +62,7 @@ class Video extends React.PureComponent {
|
|||
savePosition,
|
||||
mediaPaused,
|
||||
mediaPosition,
|
||||
positions,
|
||||
} = this.props;
|
||||
|
||||
const isPlaying = playingUri === uri;
|
||||
|
@ -119,7 +120,8 @@ class Video extends React.PureComponent {
|
|||
doPlay={doPlay}
|
||||
doPause={doPause}
|
||||
savePosition={savePosition}
|
||||
id={claim.claim_id}
|
||||
claim={claim}
|
||||
uri={uri}
|
||||
paused={mediaPaused}
|
||||
position={mediaPosition}
|
||||
/>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import * as actions from "constants/action_types";
|
||||
import type { Action, Dispatch } from "redux/reducers/media";
|
||||
import lbry from "lbry";
|
||||
import { makeSelectClaimForUri } from "redux/selectors/claims";
|
||||
|
||||
export const doPlay = () => (dispatch: Dispatch) =>
|
||||
dispatch({
|
||||
|
@ -13,11 +14,17 @@ export const doPause = () => (dispatch: Dispatch) =>
|
|||
type: actions.MEDIA_PAUSE,
|
||||
});
|
||||
|
||||
export const savePosition = (id: String, position: String) => (
|
||||
dispatch: Dispatch
|
||||
) =>
|
||||
dispatch({
|
||||
type: actions.MEDIA_POSITION,
|
||||
id,
|
||||
position,
|
||||
});
|
||||
export function savePosition(claimId, position) {
|
||||
return function(dispatch: Dispatch, getState: Function) {
|
||||
const state = getState();
|
||||
const claim = state.claims.byId[claimId];
|
||||
const outpoint = `${claim.txid}:${claim.nout}`;
|
||||
dispatch({
|
||||
type: actions.MEDIA_POSITION,
|
||||
data: {
|
||||
outpoint,
|
||||
position,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ export default handleActions(
|
|||
}),
|
||||
|
||||
[actions.MEDIA_POSITION]: (state: MediaState, action: Action) => {
|
||||
const { id, position } = action;
|
||||
const { outpoint, position } = action.data;
|
||||
return {
|
||||
...state,
|
||||
positions: {
|
||||
...state.positions,
|
||||
[id]: position,
|
||||
[outpoint]: position,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as settings from "constants/settings";
|
||||
import { createSelector } from "reselect";
|
||||
import lbryuri from "lbryuri";
|
||||
import { makeSelectClaimForUri } from "redux/selectors/claims";
|
||||
|
||||
const _selectState = state => state.media || {};
|
||||
|
||||
|
@ -10,7 +11,7 @@ export const selectMediaPaused = createSelector(
|
|||
);
|
||||
|
||||
export const makeSelectMediaPositionForUri = uri =>
|
||||
createSelector(_selectState, state => {
|
||||
const obj = lbryuri.parse(uri);
|
||||
return state.positions[obj.claimId] || null;
|
||||
createSelector(_selectState, makeSelectClaimForUri(uri), (state, claim) => {
|
||||
const outpoint = `${claim.txid}:${claim.nout}`;
|
||||
return state.positions[outpoint] || null;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue