Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use ExoPlayer in React Native

Hi I'm using react native, so I needed exoplayer to show subtitle on it in android.... I added exoplayer inside my app, after that should I do something to use exoplayer as default or it will link to react-native-video ? thanks

like image 396
B1zzle Avatar asked Dec 31 '19 09:12

B1zzle


3 Answers

According to the react native video ExoPlayer documentation, there are some ExoPlayer only props. Use one of them in your app and check if they're being called or not.

like image 86
pheroMona13 Avatar answered Oct 13 '22 13:10

pheroMona13


You can change the path of the project like this.


apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
// Add below this line ↑
include ':react-native-video'  // -> you must add this line on new version
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':app'

look here for more details

It will start to use android-exoplayer

I'v also added

android:usesCleartextTraffic="true"

in AndroidManifest.xml to make it work in release builds as well.

If it doesn't help, please add

import com.brentvatne.react.ReactVideoPackage;
...


@Override
protected List<ReactPackage> getPackages() {
   List<ReactPackage> packages = new PackageList(this).getPackages();

   packages.add(new ReactVideoPackage()); // <<< This line

   return packages;
}

to MainApplication.java

like image 38
Gev Avatar answered Oct 13 '22 14:10

Gev


As of now ExoPlayer is not autolinked with react-native-video. To link it with your project and use it, create a file named react-native.config.js in your project root. Then add the following code in the file:

module.exports = {
  dependencies: {
    'react-native-video': {
      platforms: {
        android: {
          sourceDir: '../node_modules/react-native-video/android-exoplayer'
        }
      }
    }
  }
}

Hope this will work.

like image 39
Imran Avatar answered Oct 13 '22 14:10

Imran