feat(sample): add an option to make controls testable in basic sample

This commit is contained in:
olivier bouillet 2022-09-11 17:01:53 +02:00
parent c8b54f3bbe
commit 568e1806a2

View File

@ -43,6 +43,7 @@ class VideoPlayer extends Component {
selectedTextTrack: undefined, selectedTextTrack: undefined,
srcListId: 0, srcListId: 0,
loop: false, loop: false,
showRNVControls: false,
}; };
seekerWidth = 0 seekerWidth = 0
@ -258,6 +259,9 @@ class VideoPlayer extends Component {
toggleFullscreen() { toggleFullscreen() {
this.setState({ fullscreen: !this.state.fullscreen }) this.setState({ fullscreen: !this.state.fullscreen })
} }
toggleControls() {
this.setState({ showRNVControls: !this.state.showRNVControls })
}
toggleDecoration() { toggleDecoration() {
this.setState({ decoration: !this.state.decoration }) this.setState({ decoration: !this.state.decoration })
@ -558,118 +562,134 @@ class VideoPlayer extends Component {
else return <View /> else return <View />
} }
renderTopControl() {
return (<>
<Text style={[styles.controlOption]}>
{this.srcList[this.state.srcListId]?.description || 'local file'}
</Text>
<View >
<TouchableOpacity
onPress={() => {
this.toggleControls()
}}
>
<Text style={[styles.leftRightControlOption]}>{this.state.showRNVControls ? 'Hide controls' : 'Show controls'}</Text>
</TouchableOpacity>
</View>
</>)
}
renderOverlay() { renderOverlay() {
return ( return (
<> <>
{this.IndicatorLoadingView()} {this.IndicatorLoadingView()}
<View style={styles.topControls}> <View style={styles.topControls}>
<Text style={[styles.controlOption]}> <View style={styles.resizeModeControl}>{this.renderTopControl()}</View>
{this.srcList[this.state.srcListId]?.description || 'local file'}
</Text>
</View> </View>
<View style={styles.leftControls}> {!this.state.showRNVControls ? (
<View style={styles.resizeModeControl}>{this.renderLeftControl()}</View> <>
</View> <View style={styles.leftControls}>
<View style={styles.rightControls}> <View style={styles.resizeModeControl}>{this.renderLeftControl()}</View>
<View style={styles.resizeModeControl}>{this.renderRightControl()}</View> </View><View style={styles.rightControls}>
</View> <View style={styles.resizeModeControl}>{this.renderRightControl()}</View>
<View style={styles.bottomControls}> </View><View style={styles.bottomControls}>
<View style={styles.generalControls}> <View style={styles.generalControls}>
<View style={styles.generalControls}> <View style={styles.generalControls}>
<View style={styles.resizeModeControl}>{this.renderInfoControl()}</View> <View style={styles.resizeModeControl}>{this.renderInfoControl()}</View>
</View> </View>
<View style={styles.resizeModeControl}>{this.renderPause()}</View> <View style={styles.resizeModeControl}>{this.renderPause()}</View>
<View style={styles.resizeModeControl}> <View style={styles.resizeModeControl}>
{this.renderRepeatModeControl()} {this.renderRepeatModeControl()}
</View> </View>
<View style={styles.resizeModeControl}> <View style={styles.resizeModeControl}>
{this.renderFullScreenControl()} {this.renderFullScreenControl()}
</View> </View>
<View style={styles.resizeModeControl}> <View style={styles.resizeModeControl}>
{this.renderDecorationsControl()} {this.renderDecorationsControl()}
</View> </View>
</View> </View>
<View style={styles.generalControls}> <View style={styles.generalControls}>
<View style={styles.rateControl}> <View style={styles.rateControl}>
{this.renderRateControl(0.25)} {this.renderRateControl(0.25)}
{this.renderRateControl(0.5)} {this.renderRateControl(0.5)}
{this.renderRateControl(1.0)} {this.renderRateControl(1.0)}
{this.renderRateControl(1.5)} {this.renderRateControl(1.5)}
{this.renderRateControl(2.0)} {this.renderRateControl(2.0)}
</View> </View>
<View style={styles.volumeControl}> <View style={styles.volumeControl}>
{this.renderVolumeControl(0.5)} {this.renderVolumeControl(0.5)}
{this.renderVolumeControl(1)} {this.renderVolumeControl(1)}
{this.renderVolumeControl(1.5)} {this.renderVolumeControl(1.5)}
</View> </View>
<View style={styles.resizeModeControl}> <View style={styles.resizeModeControl}>
{this.renderResizeModeControl('cover')} {this.renderResizeModeControl('cover')}
{this.renderResizeModeControl('contain')} {this.renderResizeModeControl('contain')}
{this.renderResizeModeControl('stretch')} {this.renderResizeModeControl('stretch')}
</View> </View>
</View> </View>
{this.renderSeekBar()} {this.renderSeekBar()}
<View style={styles.generalControls}> <View style={styles.generalControls}>
<Text style={styles.controlOption}>AudioTrack</Text> <Text style={styles.controlOption}>AudioTrack</Text>
{this.state.audioTracks?.length <= 0 ? ( {this.state.audioTracks?.length <= 0 ? (
<Text style={styles.controlOption}>empty</Text> <Text style={styles.controlOption}>empty</Text>
) : ( ) : (
<Picker <Picker
style={styles.picker} style={styles.picker}
selectedValue={this.state.selectedAudioTrack?.value} selectedValue={this.state.selectedAudioTrack?.value}
onValueChange={(itemValue, itemIndex) => { onValueChange={(itemValue, itemIndex) => {
console.log('on audio value change ' + itemValue) console.log('on audio value change ' + itemValue);
this.setState({ this.setState({
selectedAudioTrack: { selectedAudioTrack: {
type: 'language', type: 'language',
value: itemValue, value: itemValue,
}, },
}) });
}} }}
> >
{this.state.audioTracks.map((track) => { {this.state.audioTracks.map((track) => {
return ( return (
<Picker.Item <Picker.Item
label={track.language} label={track.language}
value={track.language} value={track.language}
key={track.language} key={track.language} />
/> );
) })}
})} </Picker>
</Picker> )}
)} <Text style={styles.controlOption}>TextTrack</Text>
<Text style={styles.controlOption}>TextTrack</Text> {this.state.textTracks?.length <= 0 ? (
{this.state.textTracks?.length <= 0 ? ( <Text style={styles.controlOption}>empty</Text>
<Text style={styles.controlOption}>empty</Text> ) : (
) : ( <Picker
<Picker style={styles.picker}
style={styles.picker} selectedValue={this.state.selectedTextTrack?.value}
selectedValue={this.state.selectedTextTrack?.value} onValueChange={(itemValue, itemIndex) => {
onValueChange={(itemValue, itemIndex) => { console.log('on value change ' + itemValue);
console.log('on value change ' + itemValue) this.setState({
this.setState({ selectedTextTrack: {
selectedTextTrack: { type: 'language',
type: 'language', value: itemValue,
value: itemValue, },
}, });
}) }}
}} >
> <Picker.Item label={'none'} value={'none'} key={'none'} />
<Picker.Item label={'none'} value={'none'} key={'none'} />
{this.state.textTracks.map((track) => ( {this.state.textTracks.map((track) => (
<Picker.Item <Picker.Item
label={track.language} label={track.language}
value={track.language} value={track.language}
key={track.language} key={track.language} />
/> ))}
))} </Picker>
</Picker> )}
)} </View>
</View> </View></>
</View> ) : null
}
</> </>
) )
} }
@ -689,6 +709,7 @@ class VideoPlayer extends Component {
paused={this.state.paused} paused={this.state.paused}
volume={this.state.volume} volume={this.state.volume}
muted={this.state.muted} muted={this.state.muted}
controls={this.state.showRNVControls}
resizeMode={this.state.resizeMode} resizeMode={this.state.resizeMode}
onLoad={this.onLoad} onLoad={this.onLoad}
onProgress={this.onProgress} onProgress={this.onProgress}