suppress load video error; disable autoplay per-video after download failure
This commit is contained in:
parent
607e2d3952
commit
d43dd78821
4 changed files with 43 additions and 19 deletions
|
@ -17,6 +17,7 @@ import {
|
||||||
import { makeSelectClientSetting, selectShowNsfw } from 'redux/selectors/settings';
|
import { makeSelectClientSetting, selectShowNsfw } from 'redux/selectors/settings';
|
||||||
import { selectMediaPaused, makeSelectMediaPositionForUri } from 'redux/selectors/media';
|
import { selectMediaPaused, makeSelectMediaPositionForUri } from 'redux/selectors/media';
|
||||||
import { selectPlayingUri } from 'redux/selectors/content';
|
import { selectPlayingUri } from 'redux/selectors/content';
|
||||||
|
import { selectFileInfoErrors } from 'redux/selectors/file_info';
|
||||||
import FileViewer from './view';
|
import FileViewer from './view';
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
|
@ -34,6 +35,7 @@ const select = (state, props) => ({
|
||||||
mediaPosition: makeSelectMediaPositionForUri(props.uri)(state),
|
mediaPosition: makeSelectMediaPositionForUri(props.uri)(state),
|
||||||
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
|
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
|
||||||
searchBarFocused: selectSearchBarFocused(state),
|
searchBarFocused: selectSearchBarFocused(state),
|
||||||
|
fileInfoErrors: selectFileInfoErrors(state)
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
|
|
@ -79,10 +79,22 @@ class FileViewer extends React.PureComponent<Props> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do not play when state.content.errors[uri]
|
||||||
handleAutoplay = (props: Props) => {
|
handleAutoplay = (props: Props) => {
|
||||||
const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, play, metadata } = props;
|
const {
|
||||||
|
autoplay,
|
||||||
|
playingUri,
|
||||||
|
fileInfo,
|
||||||
|
costInfo,
|
||||||
|
isDownloading,
|
||||||
|
uri,
|
||||||
|
play,
|
||||||
|
metadata,
|
||||||
|
fileInfoErrors,
|
||||||
|
} = props;
|
||||||
|
|
||||||
const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw;
|
const playable =
|
||||||
|
autoplay && playingUri !== uri && metadata && !metadata.nsfw && !(uri in fileInfoErrors);
|
||||||
|
|
||||||
if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
|
if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
|
||||||
play(uri);
|
play(uri);
|
||||||
|
|
|
@ -171,7 +171,7 @@ export function doUpdateLoadStatus(uri, outpoint) {
|
||||||
} else {
|
} else {
|
||||||
// ready to play
|
// ready to play
|
||||||
const { total_bytes: totalBytes, written_bytes: writtenBytes } = fileInfo;
|
const { total_bytes: totalBytes, written_bytes: writtenBytes } = fileInfo;
|
||||||
const progress = writtenBytes / totalBytes * 100;
|
const progress = (writtenBytes / totalBytes) * 100;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.DOWNLOADING_PROGRESSED,
|
type: ACTIONS.DOWNLOADING_PROGRESSED,
|
||||||
|
@ -259,29 +259,37 @@ export function doLoadVideo(uri) {
|
||||||
streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout';
|
streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout';
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
dispatch(doSetPlayingUri(null));
|
dispatch(handleLoadVideoError(uri, 'timeout'));
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.LOADING_VIDEO_FAILED,
|
|
||||||
data: { uri },
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch(doNotify({ id: MODALS.FILE_TIMEOUT }, { uri }));
|
|
||||||
} else {
|
} else {
|
||||||
dispatch(doDownloadFile(uri, streamInfo));
|
dispatch(doDownloadFile(uri, streamInfo));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
dispatch(doSetPlayingUri(null));
|
dispatch(handleLoadVideoError(uri));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleLoadVideoError(uri, errorType = '') {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
// suppress error when another media is playing
|
||||||
|
const { playingUri } = getState().content;
|
||||||
|
if (!playingUri || playingUri === uri) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.LOADING_VIDEO_FAILED,
|
type: ACTIONS.LOADING_VIDEO_FAILED,
|
||||||
data: { uri },
|
data: { uri },
|
||||||
});
|
});
|
||||||
|
dispatch(doSetPlayingUri(null));
|
||||||
|
if (errorType === 'timeout') {
|
||||||
|
doNotify({ id: MODALS.FILE_TIMEOUT }, { uri });
|
||||||
|
} else {
|
||||||
dispatch(
|
dispatch(
|
||||||
doAlertError(
|
doAlertError(
|
||||||
`Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
|
`Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ import {
|
||||||
selectIsFetchingClaimListMine,
|
selectIsFetchingClaimListMine,
|
||||||
selectMyClaims,
|
selectMyClaims,
|
||||||
selectClaimsById,
|
selectClaimsById,
|
||||||
} from 'redux/selectors/claims';
|
buildURI,
|
||||||
|
} from 'lbry-redux';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { buildURI } from 'lbryURI';
|
|
||||||
|
|
||||||
export const selectState = state => state.fileInfo || {};
|
export const selectState = state => state.fileInfo || {};
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export const selectTotalDownloadProgress = createSelector(selectDownloadingFileI
|
||||||
const progress = [];
|
const progress = [];
|
||||||
|
|
||||||
fileInfos.forEach(fileInfo => {
|
fileInfos.forEach(fileInfo => {
|
||||||
progress.push(fileInfo.written_bytes / fileInfo.total_bytes * 100);
|
progress.push((fileInfo.written_bytes / fileInfo.total_bytes) * 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalProgress = progress.reduce((a, b) => a + b, 0);
|
const totalProgress = progress.reduce((a, b) => a + b, 0);
|
||||||
|
@ -195,3 +195,5 @@ export const selectSearchDownloadUris = query =>
|
||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const selectFileInfoErrors = createSelector(selectState, state => state.errors || {});
|
||||||
|
|
Loading…
Add table
Reference in a new issue