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

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

Open pierroo opened this issue 6 years ago • 16 comments

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):

  • OS: Android

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 avatar Apr 18 '20 12:04 pierroo

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... :)

pierroo avatar Apr 18 '20 13:04 pierroo

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

hussainarthuna avatar Apr 19 '20 09:04 hussainarthuna

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 avatar Apr 19 '20 10:04 pierroo

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 ?

pierroo avatar Apr 19 '20 16:04 pierroo

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

hussainarthuna avatar Apr 19 '20 16:04 hussainarthuna

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.

hussainarthuna avatar Apr 19 '20 16:04 hussainarthuna

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.

pierroo avatar Apr 19 '20 16:04 pierroo

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.

hussainarthuna avatar Apr 19 '20 16:04 hussainarthuna

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

It worked Thanks a lot.

nivas412 avatar Aug 19 '20 17:08 nivas412

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.

tushar04 avatar Oct 13 '20 10:10 tushar04

Is there any fix for this yet?

avonipenti avatar Oct 29 '20 23:10 avonipenti

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() })

JestinTChacko avatar Feb 17 '21 15:02 JestinTChacko

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

avonipenti avatar Feb 17 '21 15:02 avonipenti

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",

KiruthikaThangamuthu avatar Sep 08 '21 16:09 KiruthikaThangamuthu

any solutions?

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

Eumhongin avatar Jan 08 '22 18:01 Eumhongin