johnsonsu / react-native-sound-player

Play sound file in ReactNative
MIT License
260 stars 91 forks source link

PlayUrl(url) not working on android: FinishedPlaying called instantly #89

Open pierroo opened 4 years ago

pierroo commented 4 years ago

Describe the bug When using SoundPlayer.playUrl(url) (with url being a valid link containing the .aac audio file); the sound does not play and the listener FinishedPlaying is called instantly.

It feels like the url isn't even loaded.

Or perhaps it is, silently, because when I leave the app iddle for 5 minutes and come back and I press play again, the file plays ONCE. And then back to same issue.

The test audio is just a short sound, no more than 100Kb, with .aac format.

Platform (please complete the following information):

Extra information, if that helps:

All sound files are recorded and saved using react-native-audio, with the following parameters:

audioSettings: { SampleRate: 22050, Channels: 1, AudioQuality: "Low", AudioEncoding: "aac", MeteringEnabled: true, IncludeBase64: false, AudioEncodingBitRate: 32000 },

pierroo commented 4 years ago

Additional information, that might require a new thread actually:

It seems SO random; sometimes the playUrl doesn't work on both iOS and Android. Using the getInfo() shows a duration: 0, currentTime: 0 on audio that doesn't work; and shows the right information when the audio plays.

All these audio are the same format, can be length between 1 to 30 seconds, between 40 to 100Kb, and all stored on the same storage.

I am completely clueless...

I have big hopes on this library compared to react-native-sound; because yours use the proper MEDIA sound setting when playing on android; whereas the other library use the NOTIFICATION setting which is a big problem and this cannot be changed. That is why I came here, hopefully someone will pass by... :)

hussainarthuna commented 4 years ago

Use the version 0.10.3, it is working. I had the same problem. Now it is working.

pierroo commented 4 years ago

Use the version 0.10.3, it is working. I had the same problem. Now it is working.

You are a life saver, it does work fine rolling back to version 0.10.3! Might be interesting to investigate why?

On the other hand, although it works fine when the file / url exists; when the url is empty or broken the app freezes; and the error isn't caught in the try / catch.

Here is my logcat if anyone can help:

D/MediaPlayer(14573): java.io.FileNotFoundException: No content provider: https://firebasestorage.googleapis.com/v0/b/url-of-my-audio-file D/MediaPlayer(14573): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074) D/MediaPlayer(14573): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927) D/MediaPlayer(14573): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854) D/MediaPlayer(14573): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1085) D/MediaPlayer(14573): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1059) D/MediaPlayer(14573): at android.media.MediaPlayer.create(MediaPlayer.java:927) D/MediaPlayer(14573): at android.media.MediaPlayer.create(MediaPlayer.java:904) D/MediaPlayer(14573): at android.media.MediaPlayer.create(MediaPlayer.java:883) D/MediaPlayer(14573): at com.johnsonsu.rnsoundplayer.RNSoundPlayerModule.prepareUrl(RNSoundPlayerModule.java:182) D/MediaPlayer(14573): at com.johnsonsu.rnsoundplayer.RNSoundPlayerModule.playUrl(RNSoundPlayerModule.java:57) D/MediaPlayer(14573): at java.lang.reflect.Method.invoke(Native Method) D/MediaPlayer(14573): at java.lang.reflect.Method.invoke(Method.java:372) D/MediaPlayer(14573): at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) D/MediaPlayer(14573): at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158) D/MediaPlayer(14573): at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) D/MediaPlayer(14573): at android.os.Handler.handleCallback(Handler.java:739) D/MediaPlayer(14573): at android.os.Handler.dispatchMessage(Handler.java:95) D/MediaPlayer(14573): at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29) D/MediaPlayer(14573): at android.os.Looper.loop(Looper.java:145) D/MediaPlayer(14573): at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232) D/MediaPlayer(14573): at java.lang.Thread.run(Thread.java:818) D/MediaPlayer(14573): Couldn't open file on client side, trying server side

pierroo commented 4 years ago

Additional info:

Although it was fixed on android for sound url that exists; it is still broken randomly on iOS on some sound. REALLY random, even on some sound that does exist, some works, some don't...

Is it working perfectly for you on iOS @hussainarthuna ?

hussainarthuna commented 4 years ago

@pierroo No I’ve not tested it on iOS as my client only requires android application.

hussainarthuna commented 4 years ago

Additional info:

Although it was fixed on android for sound url that exists; it is still broken randomly on iOS on some sound. REALLY random, even on some sound that does exist, some works, some don't...

Is it working perfectly for you on iOS @hussainarthuna ?

Some sounds as in? I didn't get it.

pierroo commented 4 years ago

Sorry, by "some sounds" I meant playUrl still doesn't work on some URL (containing a sound / .aac file)

They are all the same format, often the same size and length, but yet, some does work, and some doesn't: RANDOM.

hussainarthuna commented 4 years ago

Sorry, by "some sounds" I meant playUrl still doesn't work on some URL (containing a sound / .aac file)

They are all the same format, often the same size and length, but yet, some does work, and some doesn't: RANDOM.

I've tried with Mp3's and they all work fine. Try only Mp3 and check.

nivas412 commented 4 years ago

Use the version 0.10.3, it is working. I had the same problem. Now it is working.

It worked Thanks a lot.

tushar04 commented 4 years ago

I ran into the same problem on Android. On iOS it was working as expected. Only rolling back to 0.10.3 didn't help.

What worked for me is that instead of using playUrl I used loadUrl and once the url is loaded onFinishedLoadingURL callback I manually started playing the file SoundPlayer.play().

Haven't gone into details of why is this happening, thought It may help someone.

avonipenti commented 4 years ago

Is there any fix for this yet?

JestinTChacko commented 3 years ago

I ran into the same problem on Android. On iOS it was working as expected. Only rolling back to 0.10.3 didn't help.

What worked for me is that instead of using playUrl I used loadUrl and once the url is loaded onFinishedLoadingURL callback I manually started playing the file SoundPlayer.play().

Haven't gone into details of why is this happening, thought It may help someone.

Thank you very much. I try like this it worked for me.

SoundPlayer.loadUrl(value) SoundPlayer.addEventListener('FinishedLoadingURL', ({ success, url }) => { SoundPlayer.play() })

avonipenti commented 3 years ago

This issue would be a simple fix if converted to kotlin.

KiruthikaThangamuthu commented 3 years ago

In iOS, playUrl/loadUrl not playing for random urls. Inside FinishedLoadingURL listener callback, getInfo() returns {"duration":0,"currentTime":0}. Any solution?

"react-native-sound-player": "^0.11.1",

Eumhongin commented 2 years ago

any solutions?

"react-native-sound-player": "^0.11.1"