use timeupdate instead of pause to update video state
This commit is contained in:
parent
7d29c4b91d
commit
11a5f9d1d5
4 changed files with 12 additions and 17 deletions
|
@ -45,7 +45,8 @@ const perform = dispatch => ({
|
|||
changeVolume: volume => dispatch(doChangeVolume(volume)),
|
||||
// setVideoPause: val => dispatch(setVideoPause(val)),
|
||||
doPlay: () => dispatch(doPlay()),
|
||||
doPause: (id, position) => dispatch(doPause(id, position)),
|
||||
doPause: () => dispatch(doPause()),
|
||||
savePosition: (id, position) => dispatch(savePosition(id, position)),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(Video);
|
||||
|
|
|
@ -72,10 +72,10 @@ class VideoPlayer extends React.PureComponent {
|
|||
if (mediaElement) {
|
||||
mediaElement.currentTime = position;
|
||||
mediaElement.addEventListener("play", () => this.props.doPlay());
|
||||
mediaElement.addEventListener("pause", () => {
|
||||
console.log("CURRENT TIME:", mediaElement.currentTime);
|
||||
this.props.doPause(this.props.mediaId, mediaElement.currentTime);
|
||||
});
|
||||
mediaElement.addEventListener("pause", () => this.props.doPause());
|
||||
mediaElement.addEventListener("timeupdate", () =>
|
||||
this.props.savePosition(mediaId, mediaElement.currentTime)
|
||||
);
|
||||
mediaElement.addEventListener("click", this.togglePlayListener);
|
||||
mediaElement.addEventListener(
|
||||
"loadedmetadata",
|
||||
|
|
|
@ -58,6 +58,7 @@ class Video extends React.PureComponent {
|
|||
uri,
|
||||
doPlay,
|
||||
doPause,
|
||||
savePosition,
|
||||
mediaPaused,
|
||||
mediaPosition,
|
||||
} = this.props;
|
||||
|
@ -119,6 +120,7 @@ class Video extends React.PureComponent {
|
|||
volume={volume}
|
||||
doPlay={doPlay}
|
||||
doPause={doPause}
|
||||
savePosition={savePosition}
|
||||
mediaId={mediaId}
|
||||
paused={mediaPaused}
|
||||
position={mediaPosition}
|
||||
|
|
|
@ -8,18 +8,10 @@ export const doPlay = () => (dispatch: Dispatch) =>
|
|||
type: actions.MEDIA_PLAY,
|
||||
});
|
||||
|
||||
export const doPause = (id: String, position: String) => (
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
if (id && position) {
|
||||
dispatch({
|
||||
type: actions.MEDIA_POSITION,
|
||||
id,
|
||||
position,
|
||||
});
|
||||
}
|
||||
dispatch({ type: actions.MEDIA_PAUSE });
|
||||
};
|
||||
export const doPause = () => (dispatch: Dispatch) =>
|
||||
dispatch({
|
||||
type: actions.MEDIA_PAUSE,
|
||||
});
|
||||
|
||||
export const savePosition = (id: String, position: String) => (
|
||||
dispatch: Dispatch
|
||||
|
|
Loading…
Reference in a new issue