allow text/document files to be autoplayed

This commit is contained in:
Sean Yesmunt 2019-12-10 14:45:41 -05:00
parent 486dd44b32
commit 38f837d50c
4 changed files with 25 additions and 4 deletions

View file

@ -915,5 +915,8 @@
"Recommended size is 16:9": "Recommended size is 16:9",
"Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.": "Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.",
"Loading 3D model.": "Loading 3D model.",
"Saved zip archive to /Users/sean/Downloads/.lbryum-2019-12-09T17-21-28.429Z.zip": "Saved zip archive to /Users/sean/Downloads/.lbryum-2019-12-09T17-21-28.429Z.zip"
"Saved zip archive to /Users/sean/Downloads/.lbryum-2019-12-09T17-21-28.429Z.zip": "Saved zip archive to /Users/sean/Downloads/.lbryum-2019-12-09T17-21-28.429Z.zip",
"PDF opened externally.": "PDF opened externally.",
"Click here": "Click here",
"to open it again.": "to open it again."
}

View file

@ -11,7 +11,12 @@ import {
} from 'lbry-redux';
import { makeSelectCostInfoForUri } from 'lbryinc';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { makeSelectIsPlaying, makeSelectShouldObscurePreview, selectPlayingUri } from 'redux/selectors/content';
import {
makeSelectIsPlaying,
makeSelectShouldObscurePreview,
selectPlayingUri,
makeSelectCanAutoplay,
} from 'redux/selectors/content';
import FileViewer from './view';
const select = (state, props) => ({
@ -27,6 +32,7 @@ const select = (state, props) => ({
autoplay: makeSelectClientSetting(SETTINGS.AUTOPLAY)(state),
hasCostInfo: Boolean(makeSelectCostInfoForUri(props.uri)(state)),
costInfo: makeSelectCostInfoForUri(props.uri)(state),
isAutoPlayable: makeSelectCanAutoplay(props.uri)(state),
});
const perform = dispatch => ({

View file

@ -26,6 +26,7 @@ type Props = {
autoplay: boolean,
hasCostInfo: boolean,
costInfo: any,
isAutoPlayable: boolean,
};
export default function FileViewer(props: Props) {
@ -43,6 +44,7 @@ export default function FileViewer(props: Props) {
isStreamable,
hasCostInfo,
costInfo,
isAutoPlayable,
} = props;
const cost = costInfo && costInfo.cost;
const forceVideo = ['application/x-ext-mkv', 'video/x-matroska'].includes(contentType);
@ -85,10 +87,10 @@ export default function FileViewer(props: Props) {
useEffect(() => {
const videoOnPage = document.querySelector('video');
if (autoplay && !videoOnPage && isStreamable && hasCostInfo && cost === 0) {
if (autoplay && !videoOnPage && isAutoPlayable && hasCostInfo && cost === 0) {
viewFile();
}
}, [autoplay, viewFile, isStreamable, hasCostInfo, cost]);
}, [autoplay, viewFile, isAutoPlayable, hasCostInfo, cost]);
return (
<div

View file

@ -6,6 +6,7 @@ import {
makeSelectClaimsInChannelForCurrentPageState,
makeSelectClaimIsNsfw,
makeSelectRecommendedContentForUri,
makeSelectMediaTypeForUri,
} from 'lbry-redux';
import { selectShowMatureContent } from 'redux/selectors/settings';
@ -117,3 +118,12 @@ export const makeSelectShouldObscurePreview = (uri: string) =>
return isClaimMature && !showMatureContent;
}
);
export const makeSelectCanAutoplay = (uri: string) =>
createSelector(
makeSelectMediaTypeForUri(uri),
mediaType => {
const canAutoPlay = ['audio', 'video', 'image', 'text', 'document'].includes(mediaType);
return canAutoPlay;
}
);