file page download progress display and media loading / playback tweaks

This commit is contained in:
Akinwale Ariwodola 2018-05-18 12:00:58 +01:00
parent 8db8083e32
commit 59f5b5ede3
4 changed files with 31 additions and 17 deletions

View file

@ -249,6 +249,7 @@ class MediaPlayer extends React.PureComponent {
return ( return (
<View style={[style, mediaPlayerStyle.container]}> <View style={[style, mediaPlayerStyle.container]}>
<View style={mediaPlayerStyle.playerBackground} />
<Video source={{ uri: 'file:///' + fileInfo.download_path }} <Video source={{ uri: 'file:///' + fileInfo.download_path }}
ref={(ref: Video) => { this.video = ref }} ref={(ref: Video) => { this.video = ref }}
resizeMode={this.state.resizeMode} resizeMode={this.state.resizeMode}

View file

@ -132,18 +132,22 @@ class FilePage extends React.PureComponent {
const channelClaimId = const channelClaimId =
value && value.publisherSignature && value.publisherSignature.certificateId; value && value.publisherSignature && value.publisherSignature.certificateId;
// at least 2MB (or the full download) before media can be loaded
const canLoadMedia = fileInfo && (fileInfo.written_bytes >= 2097152 || fileInfo.written_bytes == fileInfo.total_bytes); // 2MB = 1024*1024*2
return ( return (
<View style={filePageStyle.pageContainer}> <View style={filePageStyle.pageContainer}>
<View style={this.state.fullscreenMode ? filePageStyle.fullscreenMedia : filePageStyle.mediaContainer}> <View style={this.state.fullscreenMode ? filePageStyle.fullscreenMedia : filePageStyle.mediaContainer}>
{(!fileInfo || (isPlayable && !this.state.mediaLoaded)) && {(!fileInfo || (isPlayable && !canLoadMedia)) &&
<FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />} <FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />}
{isPlayable && !this.state.mediaLoaded && <ActivityIndicator size="large" color={Colors.LbryGreen} style={filePageStyle.loading} />} {isPlayable && !this.state.mediaLoaded && <ActivityIndicator size="large" color={Colors.LbryGreen} style={filePageStyle.loading} />}
{!completed && <FileDownloadButton uri={navigation.state.params.uri} style={filePageStyle.downloadButton} />} {!completed && !canLoadMedia && <FileDownloadButton uri={navigation.state.params.uri} style={filePageStyle.downloadButton} />}
{fileInfo && isPlayable && <MediaPlayer fileInfo={fileInfo} {canLoadMedia && <View style={filePageStyle.playerBackground} />}
uri={navigation.state.params.uri} {canLoadMedia && <MediaPlayer fileInfo={fileInfo}
style={filePageStyle.player} uri={navigation.state.params.uri}
onFullscreenToggled={this.handleFullscreenToggle} style={filePageStyle.player}
onMediaLoaded={() => { this.setState({ mediaLoaded: true }); }}/>} onFullscreenToggled={this.handleFullscreenToggle}
onMediaLoaded={() => { this.setState({ mediaLoaded: true }); }}/>}
</View> </View>
{ showActions && { showActions &&
<View style={filePageStyle.actions}> <View style={filePageStyle.actions}>

View file

@ -15,7 +15,16 @@ const filePageStyle = StyleSheet.create({
mediaContainer: { mediaContainer: {
alignItems: 'center', alignItems: 'center',
width: screenWidth, width: screenWidth,
height: 220, height: 220
},
playerBackground: {
position: 'absolute',
flex: 1,
left: 0,
top: 0,
right: 0,
bottom: 16,
backgroundColor: Colors.Black
}, },
emptyClaimText: { emptyClaimText: {
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
@ -71,7 +80,8 @@ const filePageStyle = StyleSheet.create({
flex: 1, flex: 1,
width: '100%', width: '100%',
height: '100%', height: '100%',
marginBottom: 14 marginBottom: 14,
zIndex: 99
}, },
fullscreenMedia: { fullscreenMedia: {
position: 'absolute', position: 'absolute',

View file

@ -1,13 +1,12 @@
import { StyleSheet, Dimensions } from 'react-native'; import { StyleSheet } from 'react-native';
const screenDimension = Dimensions.get('window');
const screenWidth = screenDimension.width;
const mediaPlayerStyle = StyleSheet.create({ const mediaPlayerStyle = StyleSheet.create({
player: { player: {
flex: 1 flex: 1
}, },
container: { container: {
marginBottom: 0,
paddingBottom: 16,
}, },
progress: { progress: {
flex: 1, flex: 1,
@ -26,7 +25,7 @@ const mediaPlayerStyle = StyleSheet.create({
height: 3, height: 3,
width: '100%', width: '100%',
position: 'absolute', position: 'absolute',
bottom: 0, bottom: 14,
left: 0, left: 0,
}, },
playerControls: { playerControls: {
@ -77,7 +76,7 @@ const mediaPlayerStyle = StyleSheet.create({
seekerCircle: { seekerCircle: {
borderRadius: 12, borderRadius: 12,
position: 'relative', position: 'relative',
top: 16, top: 14,
left: 8, left: 8,
height: 12, height: 12,
width: 12, width: 12,
@ -87,13 +86,13 @@ const mediaPlayerStyle = StyleSheet.create({
position: 'absolute', position: 'absolute',
height: 36, height: 36,
width: 36, width: 36,
bottom: -12, bottom: 0,
marginLeft: -8 marginLeft: -8
}, },
bigSeekerCircle: { bigSeekerCircle: {
borderRadius: 24, borderRadius: 24,
position: 'relative', position: 'relative',
top: 10, top: 8,
left: 8, left: 8,
height: 24, height: 24,
width: 24, width: 24,