doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.3k stars 1.02k forks source link

TypeError: null is not an object (evaluating 'TrackPlayer.RATING_HEART') #1504

Closed sjorsroelofs closed 2 years ago

sjorsroelofs commented 2 years ago

Describe the Bug When adding react-native-track-player to a new React Native project (without Expo) I get the following error:

TypeError: null is not an object (evaluating 'TrackPlayer.RATING_HEART')

Steps To Reproduce

Code To Reproduce See steps to reproduce.

Environment Info: npx react-native info

System: OS: macOS 12.2.1 CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz Memory: 30.03 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - /usr/local/bin/node Yarn: Not Found npm: 8.5.5 - /usr/local/bin/npm Watchman: 2022.03.21.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: API Levels: 30, 31 Build Tools: 30.0.2, 30.0.3, 31.0.0 System Images: android-28 | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7621141 Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.1 => 0.68.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

react-native-track-player version

^2.1.3

Real device? Or simulator? Both

What OS are you running? Android, iOS, iOS Simulator

Thanks a lot!

jspizziri commented 2 years ago

@sjorsroelofs did you follow the instructions here and here? Specifically running setupPlayer?

From your report above it's not clear to me that you did.

sjorsroelofs commented 2 years ago

Thanks for the reply. I'm now getting a different error. In index.js I added this: TrackPlayer.registerPlaybackService(() => require('./service'));

And in App.js I added this: import TrackPlayer from 'react-native-track-player'; await TrackPlayer.setupPlayer({});

The error i'm getting right now is:

Unexpected identifier '_reactNativeTrackPlayer' no stack

Am I doing something wrong in the setup? I followed the instructions, but it's not clear to me what's going wrong..

jspizziri commented 2 years ago

@sjorsroelofs did you also run a pod install in your ios directory? Just realized thats not in the docs.

sjorsroelofs commented 2 years ago

@sjorsroelofs did you also run a pod install in your ios directory? Just realized thats not in the docs.

Yeah I did, but the problem is also on Android

jspizziri commented 2 years ago

@sjorsroelofs can you take a look at the setup of the Example app and mirror what it's doing? Something seems to be wrong with how you've set it up and I'm not entirely sure what it is.

jspizziri commented 2 years ago

Also see this issue which might be related https://github.com/doublesymmetry/react-native-track-player/issues/719

sjorsroelofs commented 2 years ago

Alright, that worked! Don't know exactly what did the trick in the end.. I tried a lot of things 😅 Think there is some important part missing in the example code in the documentation. Thanks for your help!

jspizziri commented 2 years ago

@sjorsroelofs what were the important things missing in the docs? If its the case we should get them updated.

sjorsroelofs commented 2 years ago

@jspizziri Sorry, couldn't test on Android yesterday. Tried it now and getting a build error when running on an Android device:

FAILURE: Build failed with an exception. What went wrong: Could not determine the dependencies of task ':react-native-track-player:compileDebugAidl'. Could not resolve all task dependencies for configuration ':react-native-track-player:debugCompileClasspath'. Could not find com.google.android.exoplayer:exoplayer-dash:2.11.4. Searched in the following locations:

By using this issue I figured out it was solved by adding jcenter() to the Android build.gradle file.

Now I see the media controls in Android, but no music is playing. After a few seconds the controls disapear. Works perfectly on iOS though.. I'm trying to play an HLS (m3u8) stream.

topovik commented 2 years ago

Are there any solutions to this problem?

PaulCombal commented 2 years ago

I'm fairly sure this is still an issue using expo. It doesn't matter how well I follow the instructions, the error comes from this line in lib/interfaces.js:

var TrackPlayer = react_native_1.NativeModules.TrackPlayerModule;

NativeModules is:

Native Modules written in ObjectiveC/Swift/Java exposed via the RCTBridge Define lazy getters for each module. These will return the module if already loaded, or load it if not. See [https://reactnative.dev/docs/native-modules-ios](vscode-file://vscode-app/snap/code/104/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)
RatingType[RatingType["Heart"] = TrackPlayer.RATING_HEART] = "Heart";

In the code above TrackPlayer is null. The variable is not reassigned anywhere else in the file.

The documentation states that expo is supported.

I have the default expo setup as stated in the official react native docs, blank project. I can provide minimal code if needed @jspizziri .

Thank you for spending time on the issue.

EDIT:

I'm new to React Native and it shows. I was using expo go thinking this was the thing, this was clearly said that it's not in the documentation which makes me a complete retard. However, if putting a small warning "Will not work with expo go" above the expo section in the docs (even if it makes complete sense to me now) can prevent other people from figuring out what is happening like I did, maybe that could be a time saver for you. Thank you very much for your time and your work

HobaiGuigui commented 1 year ago

Try this on all "Evaluting error" Ex: 'TrackPlayer.RATING_HEART' => 'TrackPlayer?.RATING_HEART'

rickyanwar commented 1 year ago

Any solution of this in expo

ABHAY-SAKARIYA commented 6 months ago

Im also facing the error while using track player with my project in expo i tried so many solutions but did not work any for me now .. can anyone help us for this