autoplay first related

This commit is contained in:
jessop 2019-09-05 20:26:03 -04:00
parent a8fb8b82f4
commit 9d2241df27
4 changed files with 51 additions and 6 deletions

View file

@ -7,8 +7,9 @@ import {
makeSelectMediaTypeForUri,
makeSelectDownloadPathForUri,
makeSelectFileNameForUri,
makeSelectFirstRecommendedFileForUri,
} from 'lbry-redux';
import { THEME } from 'constants/settings';
import { THEME, AUTOPLAY } from 'constants/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import FileRender from './view';
@ -21,6 +22,8 @@ const select = (state, props) => ({
downloadPath: makeSelectDownloadPathForUri(props.uri)(state),
fileName: makeSelectFileNameForUri(props.uri)(state),
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
nextFileToPlay: makeSelectFirstRecommendedFileForUri(props.uri)(state),
autoplay: makeSelectClientSetting(AUTOPLAY)(state),
});
export default connect(select)(FileRender);

View file

@ -6,6 +6,8 @@ import VideoViewer from 'component/viewers/videoViewer';
import ImageViewer from 'component/viewers/imageViewer';
import AppViewer from 'component/viewers/appViewer';
import Button from 'component/button';
import { withRouter } from 'react-router-dom';
import { formatLbryUriForWeb } from 'util/uri';
// @if TARGET='web'
import { generateStreamUrl } from 'util/lbrytv';
// @endif
@ -67,6 +69,9 @@ type Props = {
currentTheme: string,
downloadPath: string,
fileName: string,
autoplay: boolean,
nextFileToPlay: string,
history: { push: string => void },
};
class FileRender extends React.PureComponent<Props> {
@ -74,6 +79,7 @@ class FileRender extends React.PureComponent<Props> {
super(props);
(this: any).escapeListener = this.escapeListener.bind(this);
(this: any).onEndedCb = this.onEndedCb.bind(this);
}
componentDidMount() {
@ -98,6 +104,13 @@ class FileRender extends React.PureComponent<Props> {
remote.getCurrentWindow().setFullScreen(false);
}
onEndedCb() {
const { autoplay, nextFileToPlay, history } = this.props;
if (autoplay && nextFileToPlay) {
history.push(formatLbryUriForWeb(nextFileToPlay));
}
}
renderViewer() {
const { mediaType, currentTheme, claim, contentType, downloadPath, fileName, streamingUrl, uri } = this.props;
const fileType = fileName && path.extname(fileName).substring(1);
@ -117,8 +130,8 @@ class FileRender extends React.PureComponent<Props> {
application: <AppViewer uri={uri} />,
// @endif
video: <VideoViewer uri={uri} source={source} contentType={contentType} />,
audio: <VideoViewer uri={uri} source={source} contentType={contentType} />,
video: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} />,
audio: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} />,
image: <ImageViewer uri={uri} source={source} />,
// Add routes to viewer...
};
@ -201,4 +214,4 @@ class FileRender extends React.PureComponent<Props> {
}
}
export default FileRender;
export default withRouter(FileRender);

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { makeSelectFileInfoForUri } from 'lbry-redux';
import { doChangeVolume, doChangeMute } from 'redux/actions/app';
import { selectVolume, selectMute } from 'redux/selectors/app';
import { savePosition } from 'redux/actions/content';
import { savePosition, doSetPlayingUri } from 'redux/actions/content';
import { makeSelectContentPositionForUri } from 'redux/selectors/content';
import VideoViewer from './view';
@ -17,6 +17,7 @@ const perform = dispatch => ({
changeVolume: volume => dispatch(doChangeVolume(volume)),
savePosition: (uri, position) => dispatch(savePosition(uri, position)),
changeMute: muted => dispatch(doChangeMute(muted)),
setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
});
export default connect(

View file

@ -14,16 +14,44 @@ const VIDEO_JS_OPTIONS = {
};
type Props = {
volume: number,
position: number,
muted: boolean,
hasFileInfo: boolean,
changeVolume: number => void,
savePosition: (string, number) => void,
changeMute: boolean => void,
setPlayingUri: (string | null) => void,
source: string,
contentType: string,
hasFileInfo: boolean,
onEndedCB: any,
};
function VideoViewer(props: Props) {
const { contentType, source } = props;
const { contentType, source, setPlayingUri, onEndedCB } = props;
const videoRef = useRef();
const [requireRedraw, setRequireRedraw] = useState(false);
useEffect(() => {
const currentVideo: HTMLVideoElement | null = document.querySelector('video');
function doEnded() {
setPlayingUri(null);
onEndedCB();
}
if (currentVideo) {
currentVideo.addEventListener('ended', doEnded);
}
// cleanup function:
return () => {
if (currentVideo) {
currentVideo.removeEventListener('ended', doEnded);
}
};
}, []);
useEffect(() => {
const videoNode = videoRef.current;
const videoJsOptions = {