react-native-sound icon indicating copy to clipboard operation
react-native-sound copied to clipboard

Not playing on android

Open ofirgeller opened this issue 8 years ago • 22 comments
trafficstars

Im on "react-native-sound": "0.10.1"

Calling play does not produce sound and the callback is invoked with the value false. coming from the onError listener in RNSoundModule.

Happens on both an emulator and a device. sdk 19 and 25.

Before that i was using the version from TheGhoul21 fork and the sound did play.

The player returns true when I check for IsLoaded() .

and sadly There is no more information i can give. if someone points me in the right direction so I can try editing the js and/or android code to fix the problem.

example file: https://languagezenstorage.blob.core.windows.net/media0/xgcUXjHhP8.mp3

ofirgeller avatar May 10 '17 08:05 ofirgeller

File name must be all lowercase

Android: Save your sound clip files under the directory android/app/src/main/res/raw. Note that files in this directory must be lowercase and underscored (e.g. my_file_name.mp3) and that subdirectories are not supported by Android.

njwest avatar May 10 '17 12:05 njwest

@njwest
This is not a local file. so the limit is not set in stone, files in the wild are case sensitive. My memory was that this "feature" of lower casing the input path was removed. it's a real problem otherwise.

ofirgeller avatar May 10 '17 13:05 ofirgeller

I checked the source again, the file name used unchanged (this is good). but It still does not play and no useful information is given as for the problem.

ofirgeller avatar May 12 '17 15:05 ofirgeller

Can you post your code? I'm running an Android app with 0.10.1 right now and it's playing audio without problems.

benvium avatar May 12 '17 15:05 benvium

Sure

this.recording= new Sound(path, MEDIA_URI, (error) => {
        if (error) {
            console.log('failed to create  sound', error);
            return;
        }

        console.log('sound is loaded: ', recording.isLoaded());
    });

Later

  recording.play((success) => {
        if (success === true) {
            console.log('successfully finished playing');
        } else {
            console.log('play  failed due to unknown reason ' + success);
        }
    });

The value of recording.isLoaded() is true before I call play.

I edited the android code to return the error codes and not just "false" when the onError delegate is invoked.

The error Android is throwing is (-38,0),

ofirgeller avatar May 12 '17 17:05 ofirgeller

Thanks - I'm debugging an Android device while trying to load a networked resource, and I'm seeing:

05-12 18:39:23.260 23518-23553/com.rnsounddemo I/RNSoundModule: https://languagezenstorage.blob.core.windows.net/media0/xgcUXjHhP8.mp3
05-12 18:39:34.963 23518-23553/com.rnsounddemo E/MediaPlayer: Attempt to call getDuration in wrong state: mPlayer=0xcf790b80, mCurrentState=2

My suspicion is that the changes introduced in #169 are causing this (removed the .prepare method). I'll investigate.

benvium avatar May 12 '17 17:05 benvium

@ofirgeller Well, suspicion confirmed. Adding .prepare() back in if it's a remote URL does indeed make it play. However, at least in debug mode, the whole app is blocked while the HTTP request is made. If you turn off Wifi the whole app pauses for 10-20 seconds. This obviously isn't great

benvium avatar May 12 '17 17:05 benvium

@benvium This makes a lot of sense, when I was solving the same problem using Xamarin I had to call prepare to make it work, I then wrapped the call into a different thread to avoid the blocking.,

var prepreTask = Task.Run(() => player.Prepare());

Can we try doing the same thing in java?

ofirgeller avatar May 12 '17 18:05 ofirgeller

@benvium I'm giving a shot to fixing it. will update here if I give up

ofirgeller avatar May 12 '17 19:05 ofirgeller

@ofirgeller I've been having a go too - I can get it to work using .prepareAsync instead, but then using require() to play an audio no longer works :-(

benvium avatar May 12 '17 19:05 benvium

@benvium How do you use require? from js? can you are the code that stops working so I can test it as well?

ofirgeller avatar May 12 '17 19:05 ofirgeller

Sure, take a look at the branch fix_android_network_sound at https://github.com/zmxv/react-native-sound/tree/fix_android_network_sound

I've been testing with the try-android-download-fix branch of https://github.com/zmxv/react-native-sound-demo/tree/try-android-download-fix If you pull that you'll need to update the package.json to point to the branch above (haven't done that yet).

benvium avatar May 12 '17 19:05 benvium

@benvium I think ill stop now as otherwise we are going to have a merge-fest

If you want you can skype me (ofir.geller) and we can work on it together for a while. if not I prefer waiting until the code is no longer in flex.

ofirgeller avatar May 12 '17 20:05 ofirgeller

Facing the same issue. Trying to load an audio from an amazon s3 URL. Facing issue in Android alone. Error message reads - resource not found. Any solution for this?

SoorajChandran avatar May 17 '17 16:05 SoorajChandran

Hi guys, can we please merge #184 until it is fixed properly? Blocking is not a big deal for my app since I load all my sounds when it boots, before any UI is rendered. I can see how that would be a problem for a music player, but blocking is better than silence.

ndbroadbent avatar May 19 '17 19:05 ndbroadbent

I updated #184 to use prepareAsync, which is a better stop-gap for now

ndbroadbent avatar May 20 '17 17:05 ndbroadbent

Sounds are not working on Android yet. Any updates?

rohitgoyal avatar Jun 14 '17 11:06 rohitgoyal

Same issue. Only sounds from the network are working on Android.

marcosschroh avatar Oct 17 '17 09:10 marcosschroh

I'm giving up on this library for Android, for now at least..

adamski avatar Mar 13 '18 12:03 adamski

Me too :(

Narutuffy avatar Sep 08 '18 10:09 Narutuffy

Try testing in different android version. I just found this is not working on android 4.4. So I'll hide our audio feature for those users :(

MaxiSantos avatar Oct 01 '18 14:10 MaxiSantos

You can add a folder called raw in android/app/src/main/res and put a copy of the audio file in it.

ProgrammerNephi avatar Mar 08 '24 22:03 ProgrammerNephi