react-native-sound
react-native-sound copied to clipboard
Not playing on android
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
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
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.
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.
Can you post your code? I'm running an Android app with 0.10.1 right now and it's playing audio without problems.
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),
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.
@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 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?
@benvium I'm giving a shot to fixing it. will update here if I give up
@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 How do you use require? from js? can you are the code that stops working so I can test it as well?
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 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.
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?
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.
I updated #184 to use prepareAsync, which is a better stop-gap for now
Sounds are not working on Android yet. Any updates?
Same issue. Only sounds from the network are working on Android.
I'm giving up on this library for Android, for now at least..
Me too :(
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 :(
You can add a folder called raw in android/app/src/main/res and put a copy of the audio file in it.