react-native-media-player
react-native-media-player copied to clipboard
Does not work on react 0.55.x also with the latest RNFS
doesnt work on the latest version of react,overrides a missing method, also the example app your using doesnt support the latest RNFS, signatures have changed.
can you provide a more up to date example
I was able to build this for Android, had to do a few of changes after installing:
In settings.gradle
in root of your android project
include ':react-native-media-player'
project(':react-native-media-player').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-media-player/android')
In build.gradle
extend dependencies with
dependencies {
implementation project(':react-native-fs')
implementation project(':react-native-media-player')
...
}
replace contents of RNMediaPlayerPackage.java
with newer format
package com.mybigday.rnmediaplayer;
import java.util.*;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
public class RNMediaPlayerPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RNMediaPlayer(reactContext));
return modules;
}
}
Sync, clean, build and test. I wasn't able to play a video tho. It looks like this player expects local files so if you want to play some video from a server first download using RNFS then play the local file. Whenever a file is passed to the MediaPlayer my app would crash
let containerId = await MediaPlayer.pushVideo(`${RNFS.ExternalDirectoryPath}/${"f12b2c5365ac460099b8df241886bbbd.mp4"}`, MediaPlayer.PUSH_WAY.ClearOther);
resulting in this exception in Logcat
java.lang.UnsupportedOperationException: TextureView doesn't support displaying a background drawable
at android.view.TextureView.setBackgroundDrawable(TextureView.java:326)
at android.view.View.setBackground(View.java:22721)
at android.view.View.setBackgroundColor(View.java:22683)
at com.mybigday.rnmediaplayer.VideoContainer.<init>(VideoContainer.java:19)
at com.mybigday.rnmediaplayer.Root.finalRendIn(Root.java:31)
at com.mybigday.rnmediaplayer.Root.rendIn(Root.java:55)
at com.mybigday.rnmediaplayer.RNMediaPlayer$7.run(RNMediaPlayer.java:143)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
This above points to some changes in Android itself were newer API break this old player's functionality. To fix this we need to go deep into the JAVA real ..