diff --git a/VideoPlayers b/VideoPlayers new file mode 100644 index 00000000..bdd0c5a7 --- /dev/null +++ b/VideoPlayers @@ -0,0 +1,1520 @@ +import React, {Component} from 'react'; +import Video from 'react-native-video'; +import { + TouchableWithoutFeedback, + TouchableHighlight, + ImageBackground, + PanResponder, + StyleSheet, + Animated, + SafeAreaView, + Easing, + Image, + View, + Text, + TouchableOpacity, Platform +} from 'react-native'; +import padStart from 'lodash/padStart'; +import Icon from 'react-native-vector-icons/MaterialIcons'; + + +export default class VideoPlayer extends Component { + static defaultProps = { + toggleResizeModeOnFullscreen: true, + controlAnimationTiming: 500, + doubleTapTime: 13, + playInBackground: false, + playWhenInactive: false, + resizeMode: 'contain', + isFullscreen: false, + showOnStart: true, + paused: false, + repeat: false, + muted: false, + volume: 1, + title: '', + rate: 1, + }; + + constructor(props) { + super(props); + + /** + * All of our values that are updated by the + * methods and listeners in this class + */ + this.state = { + // Video + resizeMode: this.props.resizeMode, + paused: this.props.paused, + muted: this.props.muted, + volume: this.props.volume, + rate: this.props.rate, + // Controls + + isFullscreen: + this.props.isFullScreen || this.props.resizeMode === 'cover' || false, + showTimeRemaining: true, + volumeTrackWidth: 0, + volumeFillWidth: 0, + seekerFillWidth: 0, + showControls: this.props.showOnStart, + volumePosition: 0, + seekerPosition: 0, + volumeOffset: 0, + seekerOffset: 0, + seeking: false, + originallyPaused: false, + scrubbing: false, + loading: false, + currentTime: 0, + error: false, + duration: 0, + width: 200, + }; + + /** + * Any options that can be set at init. + */ + this.opts = { + playWhenInactive: this.props.playWhenInactive, + playInBackground: this.props.playInBackground, + repeat: this.props.repeat, + title: this.props.title, + }; + + /** + * Our app listeners and associated methods + */ + this.events = { + onError: this.props.onError || this._onError.bind(this), + onBack: this.props.onBack || this._onBack.bind(this), + onEnd: this.props.onEnd || this._onEnd.bind(this), + onScreenTouch: this._onScreenTouch.bind(this), + onEnterFullscreen: this.props.onEnterFullscreen, + onExitFullscreen: this.props.onExitFullscreen, + onShowControls: this.props.onShowControls, + onHideControls: this.props.onHideControls, + onLoadStart: this._onLoadStart.bind(this), + onProgress: this._onProgress.bind(this), + onSeek: this._onSeek.bind(this), + onLoad: this._onLoad.bind(this), + onPause: this.props.onPause, + onPlay: this.props.onPlay, + }; + + /** + * Functions used throughout the application + */ + this.methods = { + toggleFullscreen: this._toggleFullscreen.bind(this), + togglePlayPause: this._togglePlayPause.bind(this), + toggleControls: this._toggleControls.bind(this), + toggleTimer: this._toggleTimer.bind(this), + }; + + /** + * Player information + */ + this.player = { + controlTimeoutDelay: this.props.controlTimeout || 15000, + volumePanResponder: PanResponder, + seekPanResponder: PanResponder, + controlTimeout: null, + tapActionTimeout: null, + volumeWidth: 150, + iconOffset: 0, + seekerWidth: 0, + ref: Video, + scrubbingTimeStep: this.props.scrubbing || 0, + tapAnywhereToPause: this.props.tapAnywhereToPause, + }; + + /** + * Various animations + */ + const initialValue = this.props.showOnStart ? 1 : 0; + + this.animations = { + bottomControl: { + marginBottom: new Animated.Value(0), + opacity: new Animated.Value(initialValue), + }, + topControl: { + marginTop: new Animated.Value(0), + opacity: new Animated.Value(initialValue), + }, + video: { + opacity: new Animated.Value(1), + }, + loader: { + rotate: new Animated.Value(0), + MAX_VALUE: 360, + }, + }; + + /** + * Various styles that be added... + */ + this.styles = { + videoStyle: this.props.videoStyle || {}, + containerStyle: this.props.style || {}, + }; + } + + componentDidUpdate = prevProps => { + const {isFullscreen} = this.props; + + if (prevProps.isFullscreen !== isFullscreen) { + this.setState({ + isFullscreen, + }); + } + }; + /** + | ------------------------------------------------------- + | Events + | ------------------------------------------------------- + | + | These are the events that the