React-native-track-player: BUG!! Not giving Audio Output on Physical Device after Generating Release Apk

Created on 31 Jan 2018  路  36Comments  路  Source: react-native-kit/react-native-track-player

This is not giving audio output on Real physical device but works fine in Emulator.

Main File
....
```
TrackPlayer.setupPlayer().then(async () => {

        // Adds a track to the queue
        await TrackPlayer.add({
            id: '11',

            // url: 'http://example.com/avaritia.mp3', // Load media from the network
            url: require('./../../AppAssets/songstest/AR.mp3'), // Load media from the app bundle

            title: 'Humpi',
            artist: 'AR',
            album: 'Carnival of Carvings',
            genre: 'Melody',
            date: '2018-01-20T07:00:00+00:00', // RFC 3339


            artwork: require('./../../AppAssets/images/xyz.jpg'), // Load artwork from the app bundle
        });
....

onPressPlay = () => {
TrackPlayer.play();
}

....
index.js

AppRegistry.registerComponent('MyProject', () => AppNavigator);
AppRegistry.registerHeadlessTask('TrackPlayer', () => require('./player-handler.js'));
```

Android Bug

Most helpful comment

same issue here, with android but with an streaming url, app works fine on debug mode, but on release after init the TrackSetup, app crashes

All 36 comments

@Guichaguri Please give a fixing idea

iOS or Android?

Android only. Checked on multiple devices with same code.
@Guichaguri insights please

For your information, Its happening with Release Apk.

Do URLs work? Is it just with files from the app bundle?

Yes, URL works Seamlessly . The problem is only while working with bundle files and that too after making release apk.
Not giving audio in both emulator and physical device. I'm working in Windows machine.

Can you log the result of the require? Something like console.log(require('./../../AppAssets/songstest/AR.mp3'));

Even better:

import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';

console.log(resolveAssetSource(require('./../../AppAssets/songstest/AR.mp3')));

@Guichaguri It is not working and giving expected output.

What is it outputting?

@Guichaguri I'm trying to replicate your demo project .I will update you the progress with relevant to this

Console for the music file with resolveAssetSource

This File Refers To ::{"__packager_asset":true,"uri":"http://10.x.x.x:8081/assets/src/AppAssets/songstest/ar.mp3?platform=android&hash=c115f2e73bc5417ff393fda331347d63","scale":1}

Its running fine in Debug not in Release APK again

It will be fine if you could give sample code without redux implementation.

And what does it outputs in a release apk?

@Guichaguri I have added a demo project in a public repository for you.
I feel you can catch with a glimpse over it.

https://[email protected]/deva11/trackplayertest.git

You may clone it..

in reference to react-native-sound .I am aware that music files should keep in android/app/src/main/res/raw folder and while bundling assets in react-native folders will be merging with android native folders.

How can I match it up with it with your library.

Debug : Mode

screenshot_1518586270

Release Mode

screenshot_1518586019

@Guichaguri update please

It would be helpful if you cud give a push to the solution

same issue here, with android but with an streaming url, app works fine on debug mode, but on release after init the TrackSetup, app crashes

I'll check it out when I have time

We are waiting for it!..

after my testing the issue appear on release apk even it is returning the same resources id and that's strange,

I tried to use different source files such as import or require or even i put the files in raw folder and i call using uri such as
{uri:'file:///android_asset/test.mp3'}

and all didn't work on release version

@Guichaguri How the url gets changed !? made the apk with Same code !

@deva11 he is closing my issue post as it is same of current one, i said that track url is different and i mean that on release the files location is changed but the track player is returning same resource ID.

Okay okay! Fine @MohammadElKhatib .

Did anybody find how to fix this? :( It looks there are some issues with how resources are packaged.

Looks like the issue happens because react-native changed the way resources are packaged. In the past everything was drawable. But now resources are packaged as raw.

ResourceDrawableIdHelper helper = ResourceDrawableIdHelper.getInstance();
int id = helper.getResourceDrawableId(context, uri);

This code does not work in release.

Is this still an issue?

@dcvz were there any commits changing the behaviour? Non-image resources are packaged as raw. Although if you want to bundle a lot of audio in APK itself, you might have more issues with the fact that APK can only be 100 mb large, and you need to use expansion files and generate paths for content provider for example.

is this still an issue?

Yes. Because resources are packaged not as drawables in newest RN. https://github.com/react-native-kit/react-native-track-player/blob/e217c74b11772dc32d0d08236ec3feaeb606748a/android/src/main/java/com/guichaguri/trackplayer/service/Utils.java#L65-L77 this code is wrong. It should try to search resource in raw first.

Hi, when problem will be solved? There is a way to work around the problem? It is works in dev version of package? Because on 1.0.0 I have this problem (With React Native 0.57.5)

Sorry for taking too long to look into this.

In release mode, RN used to copy all resources to the drawable directory, and this module used to look up the files there.
It became a problem when RN started to copy non-image files into the raw directory.

same issue here, with android but with an streaming url, app works fine on debug mode, but on release after init the TrackSetup, app crashes

Wondering ..Were you able to fix it?

Hi,
I have the same problem on Android with a release apk loading a url live stream, is there a way to fix it ?

Thanks.

Problem solve, due to http instead of https in the streaming url

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simenJohnsen picture simenJohnsen  路  3Comments

tarahiw picture tarahiw  路  3Comments

JakeMotta picture JakeMotta  路  3Comments

mnlbox picture mnlbox  路  4Comments

elioscordo picture elioscordo  路  3Comments