implement touch to seek for media playback using the seek bar (#271)
This commit is contained in:
parent
a34a8136c2
commit
7313e2d1c4
4 changed files with 39 additions and 5 deletions
|
@ -1,9 +1,10 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { Text, TouchableOpacity, View } from 'react-native';
|
||||
import { ActivityIndicator, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { formatCredits } from 'lbry-redux'
|
||||
import Address from '../address';
|
||||
import Button from '../button';
|
||||
import Colors from '../../styles/colors';
|
||||
import floatingButtonStyle from '../../styles/floatingButton';
|
||||
|
||||
type Props = {
|
||||
|
@ -17,6 +18,7 @@ class FloatingWalletBalance extends React.PureComponent<Props> {
|
|||
return (
|
||||
<TouchableOpacity style={[floatingButtonStyle.container, floatingButtonStyle.bottomRight]}
|
||||
onPress={() => navigation && navigation.navigate({ routeName: 'Wallet' })}>
|
||||
{isNaN(balance) && <ActivityIndicator size="small" color={Colors.White} />}
|
||||
<Text style={floatingButtonStyle.text}>
|
||||
{(balance || balance === 0) && (formatCredits(balance, 2) + ' LBC')}
|
||||
</Text>
|
||||
|
|
|
@ -295,6 +295,17 @@ class MediaPlayer extends React.PureComponent {
|
|||
return encodedFilePath;
|
||||
}
|
||||
|
||||
onSeekerTouchAreaPressed = (evt) => {
|
||||
if (evt && evt.nativeEvent) {
|
||||
const newSeekerPosition = evt.nativeEvent.locationX;
|
||||
if (!isNaN(newSeekerPosition)) {
|
||||
const time = this.state.duration * (newSeekerPosition / this.seekerWidth);
|
||||
this.setSeekerPosition(newSeekerPosition);
|
||||
this.seekTo(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
|
||||
const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth;
|
||||
|
@ -348,6 +359,10 @@ class MediaPlayer extends React.PureComponent {
|
|||
{ left: this.state.seekerPosition }]} { ...this.seekResponder.panHandlers }>
|
||||
<View style={this.state.seeking ? mediaPlayerStyle.bigSeekerCircle : mediaPlayerStyle.seekerCircle} />
|
||||
</View>
|
||||
<TouchableOpacity
|
||||
style={[mediaPlayerStyle.seekerTouchArea,
|
||||
(this.state.fullscreenMode ? mediaPlayerStyle.seekerTouchAreaFs : mediaPlayerStyle.seekerTouchAreaContained)]}
|
||||
onPress={this.onSeekerTouchAreaPressed} />
|
||||
</View>}
|
||||
</View>
|
||||
);
|
||||
|
|
|
@ -229,6 +229,10 @@ class FilePage extends React.PureComponent {
|
|||
const isLandscape = screenWidth > screenHeight;
|
||||
this.setState({ isLandscape });
|
||||
|
||||
if (!this.playerBackground) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLandscape) {
|
||||
this.playerBackground.setNativeProps({ height: screenHeight - StyleSheet.flatten(uriBarStyle.uriContainer).height });
|
||||
} else if (this.state.playerBgHeight > 0) {
|
||||
|
|
|
@ -39,7 +39,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
|||
},
|
||||
fullscreenTrackingControls: {
|
||||
alignSelf: 'center',
|
||||
width: '70%'
|
||||
width: '60%'
|
||||
},
|
||||
playerControls: {
|
||||
position: 'absolute',
|
||||
|
@ -75,7 +75,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
|||
position: 'absolute',
|
||||
left: 8,
|
||||
bottom: 24,
|
||||
fontSize: 12,
|
||||
fontSize: 14,
|
||||
color: '#ffffff'
|
||||
},
|
||||
totalDuration: {
|
||||
|
@ -83,7 +83,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
|||
position: 'absolute',
|
||||
right: 40,
|
||||
bottom: 24,
|
||||
fontSize: 12,
|
||||
fontSize: 14,
|
||||
color: '#ffffff'
|
||||
},
|
||||
seekerCircle: {
|
||||
|
@ -100,7 +100,8 @@ const mediaPlayerStyle = StyleSheet.create({
|
|||
position: 'absolute',
|
||||
height: 36,
|
||||
width: 48,
|
||||
marginLeft: -18
|
||||
marginLeft: -18,
|
||||
zIndex: 20
|
||||
},
|
||||
seekerHandleContained: {
|
||||
bottom: -17
|
||||
|
@ -108,6 +109,18 @@ const mediaPlayerStyle = StyleSheet.create({
|
|||
seekerHandleFs: {
|
||||
bottom: 0
|
||||
},
|
||||
seekerTouchArea: {
|
||||
position: 'absolute',
|
||||
height: 30,
|
||||
width: '100%',
|
||||
zIndex: 10,
|
||||
},
|
||||
seekerTouchAreaContained: {
|
||||
bottom: -15,
|
||||
},
|
||||
seekerTouchAreaFs: {
|
||||
bottom: 0
|
||||
},
|
||||
bigSeekerCircle: {
|
||||
borderRadius: 24,
|
||||
position: 'relative',
|
||||
|
|
Loading…
Reference in a new issue