Playable downloads #111

Merged
akinwale merged 7 commits from playable-downloads into master 2020-01-16 22:00:34 +01:00
Showing only changes of commit bea29e81e1 - Show all commits

View file

@ -163,7 +163,6 @@ class FilePage extends React.PureComponent {
notify, notify,
drawerStack: prevDrawerStack, drawerStack: prevDrawerStack,
} = this.props; } = this.props;
const { uri } = navigation.state.params;
const { const {
currentRoute: prevRoute, currentRoute: prevRoute,
failedPurchaseUris, failedPurchaseUris,
@ -174,6 +173,7 @@ class FilePage extends React.PureComponent {
drawerStack, drawerStack,
resolveUris, resolveUris,
} = nextProps; } = nextProps;
const uri = this.getPurchaseUrl();
if (Constants.ROUTE_FILE === currentRoute && currentRoute !== prevRoute) { if (Constants.ROUTE_FILE === currentRoute && currentRoute !== prevRoute) {
this.onComponentFocused(); this.onComponentFocused();
@ -207,7 +207,7 @@ class FilePage extends React.PureComponent {
NativeModules.UtilityModule.checkDownloads(); NativeModules.UtilityModule.checkDownloads();
} }
if (!this.state.streamingMode && isPlayable) { if ((!fileInfo || (fileInfo && !fileInfo.completed)) && !this.state.streamingMode && isPlayable) {
if (streamingUrl) { if (streamingUrl) {
this.setState({ streamingMode: true, currentStreamUrl: streamingUrl }); this.setState({ streamingMode: true, currentStreamUrl: streamingUrl });
} else if (fileInfo && fileInfo.streaming_url) { } else if (fileInfo && fileInfo.streaming_url) {
@ -235,14 +235,6 @@ class FilePage extends React.PureComponent {
const { fileInfo: prevFileInfo } = this.props; const { fileInfo: prevFileInfo } = this.props;
const { fileInfo } = nextProps; const { fileInfo } = nextProps;
if (this.state.playbackStarted && nextProps.position) {
return false;
}
if (prevFileInfo && fileInfo && prevFileInfo.download_path === fileInfo.download_path) {
return false;
}
return ( return (
Object.keys(this.difference(nextProps, this.props)).length > 0 || Object.keys(this.difference(nextProps, this.props)).length > 0 ||
Object.keys(this.difference(nextState, this.state)).length > 0 Object.keys(this.difference(nextState, this.state)).length > 0
@ -467,8 +459,8 @@ class FilePage extends React.PureComponent {
playerUriForFileInfo = fileInfo => { playerUriForFileInfo = fileInfo => {
const { streamingUrl } = this.props; const { streamingUrl } = this.props;
if (!this.state.playbackStarted && fileInfo && fileInfo.download_path && fileInfo.completed) { if (!this.state.streamingMode && fileInfo && fileInfo.download_path && fileInfo.completed) {
// take playbackStarted in the state into account because if the download completes while // take streamingMode in the state into account because if the download completes while
// the media is already streaming, it will restart from the beginning // the media is already streaming, it will restart from the beginning
return this.getEncodedDownloadPath(fileInfo); return this.getEncodedDownloadPath(fileInfo);
} }
@ -741,8 +733,11 @@ class FilePage extends React.PureComponent {
const localFileUri = this.localUriForFileInfo(fileInfo); const localFileUri = this.localUriForFileInfo(fileInfo);
const mediaType = Lbry.getMediaType(contentType); const mediaType = Lbry.getMediaType(contentType);
const isViewable = mediaType === 'image' || mediaType === 'text'; const isViewable = mediaType === 'image' || mediaType === 'text';
const isPlayable = mediaType === 'video' || mediaType === 'audio';
if (isViewable) { if (isViewable) {
this.openFile(localFileUri, mediaType, contentType); this.openFile(localFileUri, mediaType, contentType);
} else if (isPlayable) {
notify({ message: __('Please press the Play button.') });
} else { } else {
notify({ message: __('This file cannot be displayed in the LBRY app.') }); notify({ message: __('This file cannot be displayed in the LBRY app.') });
} }
@ -1216,7 +1211,6 @@ class FilePage extends React.PureComponent {
{!completed && {!completed &&
fileInfo && fileInfo &&
!fileInfo.stopped &&
fileInfo.written_bytes > 0 && fileInfo.written_bytes > 0 &&
fileInfo.written_bytes < fileInfo.total_bytes && fileInfo.written_bytes < fileInfo.total_bytes &&
!this.state.stopDownloadConfirmed && ( !this.state.stopDownloadConfirmed && (