A video player based on react-native-video

A video player based on react-native-video

A video player based on react-native-video (swipe up and down to change the volume, screen brightness, cache progress, double-click to pause, etc. ios Android)

react-native-rn-videoplayer

  • Slide up and down the video to adjust the volume and screen brightness, slide left and right and drag the progress bar to adjust the video progress, video control lock, full screen switching, cache progress, double-click video pause, and other functions, based on react-native-video

  • ps: Android changes the brightness without obtaining advanced permissions. It only changes the current active, that is, the brightness of the current page. After changing the brightness, returning to another page will restore the original brightness.

  • If your video is not centered, refer to question 2046

  • Version 2.x requires react-native >= 0.60.0

  • Version 1.3.2 requires react-native <= 0.59.9

Enter the short book address to         enter the video preview

gif preview ios and android

     

add feature

  • v2.0.6 Add lock video controls, lock user operations (adjust volume/brightness, show hidden controls)
  • lockControl (true/false 默认关闭)

     

  • v2.0.8 Custom small screen status bar type fun The default status bar is immersive, with white characters on a black background, and the height of the status bar. You can view the Header component of view/index.js
<VideoPlayer
statusBar={()=>null}//不使用默认状态栏 跟当前app保持一致
statusBar={()=><Component/>}//自定义
/>
  • v2.2.1 Add gestures to slide the video area left and right (not the dots on the progress bar) to adjust the video progress
  • v2.2.5 autoPlay={false} Whether to play automatically, the default is true

Getting started

npm install react-native-rn-videoplayer --save

- - android

Open up android/app/src/main/java/[...]/MainActivity.java

+import android.content.Intent; 
+import android.content.res.Configuration;
public class MainActivity extends ReactActivity {

   ...

+ @Override
+      public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        Intent intent = new Intent("onConfigurationChanged");
+        intent.putExtra("newConfig", newConfig);
+        this.sendBroadcast(intent);
+    }
    ...
}

- - iOS

Add the following to your project's AppDelegate.m:

+#import "Orientation.h"

@implementation AppDelegate

// ...

+- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
+  return [Orientation getOrientation];
+}

@end

RN >= 0.60

ios

  cd ios 

  pod install

Android.

  • settings.gradle
  rootProject.name = 'TestPack622'
  apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

+    include ':react-native-linear-gradient'
+    project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
+    include ':react-native-svg'
+    project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
+    include ':react-native-orientation-locker'
+    project(':react-native-orientation-locker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation-locker/android')
+    include ':react-native-video'
+    project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
+    include ':react-native-system-setting'
+    project(':react-native-system-setting').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-system-setting/android')

  include ':app'
  • MainApplication.java
+  import com.horcrux.svg.SvgPackage;
+  import com.BV.LinearGradient.LinearGradientPackage; // <--- This!
+  import org.wonday.orientation.OrientationPackage;
+  import com.ninty.system.setting.SystemSettingPackage;
+  import com.brentvatne.react.ReactVideoPackage;

  ···
 @Override
      protected List<ReactPackage> getPackages() {
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
        // Packages that cannot be autolinked yet can be added manually here, for example:
+          packages.add(new LinearGradientPackage());
+          packages.add(new SvgPackage());
+          packages.add(new OrientationPackage());
+          packages.add(new SystemSettingPackage());
+          packages.add(new ReactVideoPackage());
        return packages;
      }
      ···
  • app/build.gradle
dependencies {
+    implementation project(':react-native-svg')
+    implementation project(':react-native-linear-gradient')
+    implementation project(':react-native-orientation-locker')
+    implementation project(':react-native-system-setting')
+    implementation project(':react-native-video')
}

RN <= 0.59

react-native link react-native-linear-gradient
react-native link react-native-orientation-locker
react-native link react-native-svg
react-native link react-native-system-setting
react-native link react-native-video
Android
  1. Append the following lines to android/settings.gradle:
include ':react-native-rn-videoplayer'
project(':react-native-rn-videoplayer').projectDir = new File(rootProject.projectDir,     '../node_modules/react-native-rn-videoplayer/android')
  1. Insert the following lines inside the dependencies block in android/app/build.gradle:
  compile project(':react-native-rn-videoplayer')
  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add
import com.ngxu.videoplayer.RNVideoplayerPackage;

new RNVideoplayerPackage() //to the list returned by the `getPackages()` method

Usage

import VideoPlayer from 'react-native-rn-videoplayer';

< VideoPlayer 
url = { "xxxxx.mp4" } 
autoPlay = { false } // Whether to play automatically, the default is true v2.2.5 add 
poster = { "http://XXX.jpg" } //Video cover 
ref = { ( ref ) => this . player = ref } 
lockControl = { true } //Control lock function v2.0.6 adds 
moreSetting = { ( )  =>  null } // More buttons in the upper right corner output null and do not display 
onSmallBack ={()=>{this.props.navigation.goBack()}}
/>

api

  • url video address

  • changeWindows() switch full screen or small screen

  • changeWindows(boolean) true full screen, false small screen

  • Example:

  <VideoPlayer ref={(ref)=>this.player=ref}/>
  this.player.changeWindows(true); // 全屏
  • The icon of the favorite button in the upper right corner of storeComponent
  storeComponent={()=><Image/>}
  • moreSetting The icon of the more button in the upper right corner
  moreSetting={()=><Image/>}
  • setPaused play pause
  this . player . setPaused ( true ) //true pause; false play;

  <VideoPlayer
   ref={(ref)=>this.player=ref}
  >
  • reLoad
  this.player.reLoad()

  <VideoPlayer
   ref={(ref)=>this.player=ref}
  >
  • rePlay reset progress to 0
this . player . reLoad ( false ) 
//false does not play automatically 
//default is true to play automatically
  • onSmallBack When the video is a small window, click the callback of the back button. You can add the function func to return to the previous page here.
  • onStore Click the callback func of the favorite button in the upper right corner
  • onMoreFun Click the callback func of the more button in the upper right corner
  • onWindowChange callback func for window change
  < VideoPlayer 
    onWindowChange = { ( e ) => { } } //e: "full" full screen "small" small screen 
  >
  • continuous Whether to turn on the selection feature when full screen is suitable for serials, the default is false
  continuous={true}
  • renderAllSeenList The list of episodes displayed after clicking the selection
···
<VideoPlayer
  url={"https://xxxxx.mp4"}
  ref={(ref)=>this.player=ref}
  renderAllSeenList={this.renderAllSeenList}
/>

···
  renderAllSeenList = () => (
  <View style={{ width: height / 2.5, backgroundColor: "rgba(0,0,0,0.6)", position: "absolute", top: 0, bottom: 0, right: 0, }}>
      <ScrollView>
        <Button 
          onPress={()=> { 
              const  newdata  =  this . state . data 
                    newdata . index  =  newindex // Episode number 
              //Update episode number and restart playing 
              this . setState ( {  data : newdata  } ,  ( )  =>  {  this . player . rePlay ( )  } ) 
          } }

        />  
      </ScrollView>      

    </View>
  )
  • NextBtnFun The method of the next episode button in full screen. When it is the last episode, the value should be changed to false and the button should be grayed out
const  { data }  =  this . state 
//data.index is the number of episodes 
//When the 
number of episodes currently played is the same as the total number of episodes, reset nextBtnFun to false nextBtnFun = { 
  data.index == data.datalist[data.datalist.length - 1].num - 1 ? false : this.nextBtnFun
  }
  • onLoad The callback that the video can start playing after loading successfully inherits react-native-veideo
  • onSeek The callback after adjusting the progress inherits onSeek of react-native-video
  • onEnd The callback after playing is inherited from react-native-video's onSeek
  • Whether onBuffer is waiting to be loaded, the video can be fetched here. It is stuck showing loading or the video can be played to hide the loading callback. Inherit the onBuffer of react-native-video
  • poster video cover image The cover image displayed when the video cannot be played is not the loading frame inherits the react-native-video poster eg:poster={" http://i1.hdslb.com/bfs/archive/[email protected] 320w_200h.jpg"}
  • ..... Inherit all the methods and properties of react-native-video

Exposure method

import {NgxuSetting} from 'react-native-rn-videoplayer'

Show or hide the virtual buttons at the bottom of Android

const Setting = new NgxuSetting()
Setting.hideAndroidBottom()
Setting.showAndroidBottom()

Get the phone system brightness

const Setting = new NgxuSetting()
Setting.getBrightness((e)=>{consoloe.log(e)})

Change ios system brightness android current app brightness

  • Android only changes the current active brightness and does not modify the system brightness. Modifying the system brightness is very troublesome. It requires the user to manually open the phone settings, app permission settings, and manually open the advanced permissions of "Allow to modify system settings"
  • ios is to change the system brightness, you can
   const Setting = new NgxuSetting()
   Setting.SetBrightness(1)//0-1之间

Download Details:

Author: A-ANing

Source Code: https://github.com/A-ANing/react-native-rn-videoplayer

react-native react mobile-apps

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Native Mobile App Development

Skenix is providing React Native Development Services with qualified React Native App Developers. Get the best React Native App Development Services.

How React Native Is Shaping Mobile App Development

Are you a mobile app developer looking for more efficient tools for your projects? Mobile app development is getting tougher and tougher as the market continues to grow. As a developer, you need to develop Apps which meet the demands of your users. To achieve this, adopt the right tools, like the React Native development framework.

Top React Native Mobile App Development Companies in USA

Looking for top React Native mobile app development company in USA for Startups & Enterprise? Find out the top list of React Native mobile app development company in USA.

Which is the best React Native app development company in New York?

Hire top react native app development company in New York to build and develop custom react native mobile apps for Android & iOS with the latest features.