You can slide up and down to change the volume, screen brightness, drag the progress bar to display the time to be changed, full-screen switching, cache progress, double-click the video to 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.
Version 2.x requires react-native >= 0.60.0
Version 1.3.2 requires react-native <= 0.59.9
npm install react-native-rn-videoplayer --save
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);
+ }
...
}
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
cd ios
pod install
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'
+ 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;
}
···
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')
}
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/settings.gradle
:include ':react-native-rn-videoplayer'
project(':react-native-rn-videoplayer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-rn-videoplayer/android')
android/app/build.gradle
: compile project(':react-native-rn-videoplayer')
android/app/src/main/java/[...]/MainApplication.java
import com.ngxu.videoplayer.RNVideoplayerPackage;
new RNVideoplayerPackage() //to the list returned by the `getPackages()` method
import Videoplayer from 'react-native-rn-videoplayer';
< VideoPlayer
url = { "https://xxxxx.mp4" }
navigation = { this . Props . Navigation } //Route the return button for small screen playback
ref = { ( ref ) => this . Player = ref }
poster = { "http:XXX.jpg" } //Video cover
/ >
url video address
continuous Whether to enable the selection function when full screen is suitable for serials, the default is false
continuous={true}
···
<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>
)
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
}
storeComponent={()=><Image/>}
moreSetting={()=><Image/>}
this . player . setPaused ( true ) //true pause; false play;
<VideoPlayer
ref={(ref)=>this.player=ref}
>
this.player.reLoad()
<VideoPlayer
ref={(ref)=>this.player=ref}
>
< VideoPlayer
onWindowChange = { ( e ) => { } } //e: "full" full screen "small" small screen
>
<VideoPlayer ref={(ref)=>this.player=ref}/>
this.player.changeWindows(true); // 全屏
import {NgxuSetting} from 'react-native-rn-videoplayer'
const Setting = new NgxuSetting()
Setting.hideAndroidBottom()
Setting.showAndroidBottom()
const Setting = new NgxuSetting()
Setting.getBrightness((e)=>{consoloe.log(e)})
const Setting = new NgxuSetting()
Setting.SetBrightness(1)//0-1之间
Author: ngxu
Live Demo: https://streamja.com/embed/ZJk5P
GitHub: https://github.com/ngxu/react-native-rn-videoplayer
#react-native #react #mobile-apps