react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

Unable to reproduce audio after build/release(android) due invalid source

Open josemojena opened this issue 2 years ago • 23 comments

Describe the Bug Hey guys, I am using the last RC(4.0.0-rc07) and I facing a problem when building in release mode in Android, in debug works fine, but soon after building using the release mode, the player is unable to resolve the path of the audios files, no matter if we use import or required, always resolve by joining the path to the assets without extension.

Steps To Reproduce How can someone else reproduce this bug? Build the apk in mode release and try to run the app on a real Android device, you will get the error message source error when hit the play button

Code To Reproduce Please provide a simple code example that allows others to replicate the bug. Just follow the react-native-track-player/tree/main/example in release mode

Replicable on Example App? Can you replicate this bug in the React Native Track Player Example App? Yes When I tried to create a release of the example, I got this error > Task :app:createBundleReleaseJsAndAssets FAILED

Environment Info: Paste the results of npx react-native info npx react-native info info Fetching system and libraries information... System: OS: macOS 13.1 CPU: (8) arm64 Apple M1 Memory: 58.89 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.10.0 - ~/.nvm/versions/node/v18.10.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.10.0/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v18.10.0/bin/npm Watchman: 2023.06.12.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.12.1 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 28, 29, 30, 31, 32, 33 Build Tools: 29.0.2, 30.0.3, 31.0.0, 33.0.0 System Images: android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a, android-33 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.12 => 0.69.12 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found Paste the exact react-native-track-player version you are using react-native-track-player : ^4.0.0-rc07 Real device? Or simulator? Real device(Samsung S22 Ultra) What OS are you running? Android

How I can Help What can you do to help resolve this? Have you investigated the underlying JS or Swift/Android code causing this bug? Can you create a Pull Request with a fix?

josemojena avatar Aug 17 '23 11:08 josemojena

Hey guys I would like to add that the Rc 4.0.0-rc05 works fine in release mode.

josemojena avatar Aug 17 '23 21:08 josemojena

FYI v4.0.0-rc07 works as expected for me in release mode with local tracks. I use rn-fetch-blob to get the base path.

uzegonemad avatar Aug 18 '23 16:08 uzegonemad

Thanks for the answer @uzegonemad, in my case, I'm using the same way as the example, something like this

import question1 from '../../assets/resources/question1.mp3' also the other way const question1 = require('../../assets/resources/question1.mp3'), this last work well in the version 3.2 and also in the v4.0.0-rc05

Could you show me an example of how to load the local file using the package n-fetch-blob?

josemojena avatar Aug 18 '23 16:08 josemojena

Wondering if this is the same issue I'm having on Android with no longer being able to play audio while using v4.0.0-rc07. Not 100% sure yet what is causing it, just came here to see if anyone else was having any issues, but the issue exists in both debug and release for me, and only goes away whenever I use a previous release, like v4.0.0-rc06 or v4.0.0-rc05.

bradzickafoose avatar Aug 24 '23 19:08 bradzickafoose

I happen to have.a release build of the example app and can confirm it happens in the example app with rc07 Screenshot_20230825_081118_RNTP Example

And fyi with other local paths with rn fetch blob you can just put file:///... As your uri

lovegaoshi avatar Aug 25 '23 15:08 lovegaoshi

We are experiencing the same issues. We were using rc04 before trying to fix this and now gone through and tested each RC version trying to find one that works but for us, all of them throw the same error when we try to play a file downloaded with rn-fetch-blob.

Reproducable in emulator and device, in debug and release as well.

We tried playing the downloaded files with VLC on mac and also tried using expo-av to play to song in-app and they both worked fine

erik-lissen avatar Aug 31 '23 08:08 erik-lissen

I am also seeing this but do not seem to have Task :app:createBundleReleaseJsAndAssets FAILED. The app builds fine in release to the device.

JWesorick avatar Sep 06 '23 06:09 JWesorick

[4.0.0-rc08] android release mode is still here:

  • links - works
  • absolute directory path - works
  • require() - doesn't
  • ES import - doesn't

varda-altusnova avatar Sep 14 '23 11:09 varda-altusnova

The issue is related to Image.resolveAssetSource method in release mode - it returns just file name.

Does someone has an option how to workaround that properly?

varda-altusnova avatar Sep 14 '23 13:09 varda-altusnova

it should be the reverse if anything - for require() rn built with dev will return the :8081 "address" and with build it should return an int representing the imported source. Can you timber the source uri in track player.load and what do you see?

On Thu, Sep 14, 2023, 6:34 AM varda-altusnova @.***> wrote:

The issue is related to Image.resolveAssetSource method in release mode https://github.com/facebook/react-native/issues/24963 - it returns just file name.

Does someone has an option how to workaround that properly?

— Reply to this email directly, view it on GitHub https://github.com/doublesymmetry/react-native-track-player/issues/2101#issuecomment-1719464109, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVWHDGGAD5ZJGPFE523X2MBXZANCNFSM6AAAAAA3T4PXZ4 . You are receiving this because you commented.Message ID: @.*** com>

lovegaoshi avatar Sep 14 '23 13:09 lovegaoshi

@lovegaoshi that's strange, but:

  • require() in both modes returns a valid number
  • when I trying to call player.load(track) - everything worked correctly (thanks for that)
  • but if I'm trying to call player.add(track); player.play() - android debug mode works ok, but in release mode background audio widget is starting, loading for a while and then just closes.

varda-altusnova avatar Sep 14 '23 14:09 varda-altusnova

uh, okay... TP.load and TP.add basically do the same thing, only add inserts track into queue but load doesnt. can you do a console.log of the Track via timber.d in MusicService.load and .add and what do you see for track.uri?

lovegaoshi avatar Sep 14 '23 14:09 lovegaoshi

Well after test with 4.0.0-rc09 still not working with local files, I will have to find another way to pass a local path to the player.

josemojena avatar Sep 24 '23 12:09 josemojena

Having the same issue even with latest release 4.4.0. It works fine when app I install from laptop in debug, but not working with signed APK.

akeditzz avatar Oct 24 '23 22:10 akeditzz

Any updated on this, my App releases are stuck. Is there any workaround ?

akshay-managooli avatar Oct 25 '23 09:10 akshay-managooli

@akshay-managooli I am using rc-04 which is the latest version when loading local files works fine.

josemojena avatar Oct 29 '23 15:10 josemojena

Same problem here. Hope the PR solves it!

bkostjens avatar Nov 06 '23 21:11 bkostjens

I tried the code change from the PR (in 4.0.1) and it works perfectly for me now.

bkostjens avatar Nov 07 '23 10:11 bkostjens

hi @bkostjens , I tried with 4.0.1, and still not able to play local files in Release app. Could you please share if you did something in code

akshaymanagooli avatar Nov 27 '23 07:11 akshaymanagooli

@akshaymanagooli I applied the changes from the pull request: https://github.com/doublesymmetry/react-native-track-player/pull/2194

Basically very minor edit, you only need to change line no 38 of trackPlayer.ts as seen here: https://github.com/doublesymmetry/react-native-track-player/pull/2194/files

bkostjens avatar Nov 27 '23 07:11 bkostjens

Thanks @bkostjens , that worked for me as well.

akshaymanagooli avatar Nov 28 '23 12:11 akshaymanagooli

@bkostjens Amazing thank you so much for sharing

tayyabrajpoot12 avatar Jan 09 '24 09:01 tayyabrajpoot12

I have the same problem on RN0.73.2 / TP 4.0.1 android works in debug but in release, play() will add the player in notfiication area (stopped --hitting play brings up a spinner that goes away after a few secs. song never plays) I edited the one line in trackplayer.js and ran yarn patch-package react-native-track-player and rebuild but the problem did not go away. Did I have to do anything in addition to that?

any help would be most appreciated

takkom avatar Jan 26 '24 15:01 takkom

This used to work for me in older versions in debug and production builds:

await TrackPlayer.add({
    url: require('../assets/sounds/my_sound.mp3')
})

From 4 point something it works with the absolute directory path by installing expo asset: npx expo install expo-asset to get the uri when adding the track:

import { Asset } from 'expo-asset'
const asset = await Asset.fromModule(require('../assets/sounds/my_sound.mp3'))
await asset.downloadAsync()

await TrackPlayer.add({
    url: asset.localUri
})

This "downloads" the file from the assets directory to the app's local cache. I would have preferred something like this: url: await Asset.fromModule(require('../assets/sounds/my_sound.mp3')).uri, but get the same error as with require.

IAmCoder avatar Feb 25 '24 21:02 IAmCoder

I have the same problem on RN0.73.2 / TP 4.0.1 android works in debug but in release, play() will add the player in notfiication area (stopped --hitting play brings up a spinner that goes away after a few secs. song never plays) I edited the one line in trackplayer.js and ran yarn patch-package react-native-track-player and rebuild but the problem did not go away. Did I have to do anything in addition to that?

any help would be most appreciated

have you solved this ? sorry for late asking

tayyabrajpoot12 avatar Feb 26 '24 14:02 tayyabrajpoot12

Works in 4.1.1 for me, fixed by https://github.com/doublesymmetry/react-native-track-player/pull/2194.

IAmCoder avatar Mar 31 '24 21:03 IAmCoder