From 1e0042f30bf48fb049ec9c763709a2cf958f9ca1 Mon Sep 17 00:00:00 2001 From: rohit singh negi Date: Mon, 25 Jan 2021 23:37:40 +0530 Subject: [PATCH] Enable exoplayer and set it as default Show loader while the video is buffering --- android/settings.gradle | 2 +- src/components/PlayerControls.js | 1 + src/components/VideoLayout.js | 24 +++++++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/android/settings.gradle b/android/settings.gradle index 9085bef..c578354 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,5 +1,5 @@ rootProject.name = 'hksj' include ':react-native-video' -project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android') +project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' diff --git a/src/components/PlayerControls.js b/src/components/PlayerControls.js index 075cc7d..ef8e6d5 100644 --- a/src/components/PlayerControls.js +++ b/src/components/PlayerControls.js @@ -50,6 +50,7 @@ const styles = StyleSheet.create({ alignContent: 'center', justifyContent: 'space-evenly', flex: 1.2, + opacity: 1, }, touchable: { padding: 5, diff --git a/src/components/VideoLayout.js b/src/components/VideoLayout.js index 4f66443..58b54b3 100644 --- a/src/components/VideoLayout.js +++ b/src/components/VideoLayout.js @@ -14,7 +14,7 @@ import RNFetchBlob from 'rn-fetch-blob'; import { BannerAdSize } from '@react-native-firebase/admob'; import Orientation from 'react-native-orientation'; import Video from 'react-native-video'; -// import Icon from "react-native-vector-icons/FontAwesome"; +import Icon from "react-native-vector-icons/FontAwesome"; import GoogleADBanner from './GoogleADBanner'; import { FullscreenClose, FullscreenOpen } from '../assets/icons'; import Header from './Header'; @@ -38,10 +38,11 @@ export default class VideoLayout extends React.Component { themeMode: this.props.themeMode }; _onLoadHandler = data => { - this.triggerBufferAnimation(); + this.setState(s => ({ ...s, duration: data.duration, + buffering: false })); }; @@ -149,7 +150,6 @@ export default class VideoLayout extends React.Component { if (this.loopingAnimation && !meta.isBuffering) { this.loopingAnimation.stopAnimation(); } - this.setState({ buffering: meta.isBuffering, }); @@ -199,6 +199,10 @@ export default class VideoLayout extends React.Component { console.log(err); } } + _onLoadStart = () => { + this.setState({ buffering: true }); + this.triggerBufferAnimation(); + } render() { const { buffering } = this.state; @@ -221,8 +225,9 @@ export default class VideoLayout extends React.Component { ref={ref => { this.player = ref; }} - // onBuffer={this._handleBuffer} + onBuffer={this._handleBuffer} onLoad={this._onLoadHandler} + onLoadStart={this._onLoadStart} style={ this.state.fullscreen ? styles.fullscreenVideo : styles.video } @@ -235,13 +240,13 @@ export default class VideoLayout extends React.Component { paused={this.state.play} resizeMode="contain" />} - {/* + {buffering && ( )} - */} + {this.state.showControls && (