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

RNSound.setSpeed

Open micahrye opened this issue 8 years ago • 12 comments

Getting error using "setSpeed" from javascript on release version running on android device. Not seeing error when running on emulator in development.

Android react-native 0.44.0

Error:

I/ReactNativeJS( 2980): GETTING = null
E/MediaPlayer( 2980): Should have subtitle controller already set
W/dalvikvm( 2980): threadid=13: thread exiting with uncaught exception (group=0x4156eba8)
E/AndroidRuntime( 2980): FATAL EXCEPTION: mqt_native_modules
E/AndroidRuntime( 2980): Process: com.cogplay, PID: 2980
E/AndroidRuntime( 2980): java.lang.RuntimeException: Could not invoke RNSound.setSpeed
E/AndroidRuntime( 2980): 	at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:382)
E/AndroidRuntime( 2980): 	at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:138)
E/AndroidRuntime( 2980): 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
E/AndroidRuntime( 2980): 	at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime( 2980): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 2980): 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
E/AndroidRuntime( 2980): 	at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 2980): 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208)
E/AndroidRuntime( 2980): 	at java.lang.Thread.run(Thread.java:841)
E/AndroidRuntime( 2980): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 2980): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2980): 	at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 2980): 	at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:368)
E/AndroidRuntime( 2980): 	... 8 more
E/AndroidRuntime( 2980): Caused by: java.lang.NoSuchMethodError: android.media.MediaPlayer.getPlaybackParams
E/AndroidRuntime( 2980): 	at com.zmxv.RNSound.RNSoundModule.setSpeed(RNSoundModule.java:161)
E/AndroidRuntime( 2980): 	... 11 more

micahrye avatar Jun 04 '17 20:06 micahrye

cc: @twitwi @benvium

rneiss avatar Jun 08 '17 21:06 rneiss

Any updates?

ohtangza avatar Jul 06 '17 14:07 ohtangza

Android "speed" is listed as both working and not working. Should this work?

Listed as available in both iOS and Android, from the readme.md table:

image

But the description lower down says iOS only:

image

lukewlms avatar Aug 03 '17 18:08 lukewlms

Which version of Android are you using? The android.media.MediaPlayer.getPlaybackParams() method is available since Android 6.0 (API Level 23), so it could have something to do with this.

gvenk avatar Aug 25 '17 21:08 gvenk

@lukecwilliams I created a new issue for your question. #257

trepidity avatar Sep 01 '17 14:09 trepidity

@trepidity thanks!

lukewlms avatar Sep 01 '17 17:09 lukewlms

+1 Release build on Android 4.42

RNSoundModule.java line 215 com.zmxv.RNSound.RNSoundModule.setSpeed

		"react": "^16.2.0",
		"react-native": "^0.53.3",
		"react-native-sound": "v0.10.2",

Crashlytics

screen shot 2018-03-09 at 9 53 12 am

esutton avatar Mar 09 '18 15:03 esutton

@ghsdh3409 Are you experiencing this issue...?

ohtangza avatar Mar 10 '18 11:03 ohtangza

@esutton Android setSpeed works in the API level >= 23.

ghsdh3409 avatar Mar 10 '18 12:03 ghsdh3409

@ghsdh3409 Thank you! My mistake.

Also I was using react-native-sound v0.10.2 which I see did not check API level.

Unfortunately I did not test on an older device until after I had made the release and started receiving crashlytics reports.

@trepidity In my case, I prefer the current behavior that returns without crashing.

But I can see the other case too; throw exception so developer who ** tests ** on older devices will know setSpeed does nothing.

esutton avatar Mar 10 '18 15:03 esutton

Now that I look at this code, I wish it had been written without the “return”. Would anyone want to write a PR and write it without the return?

On Mar 10, 2018, at 9:40 AM, Eddie [email protected] wrote:

@ghsdh3409 Thank you! My mistake.

Not sure why it threw an exception since it looked like it should have returned on an API 19 device rather than throwing?

@ReactMethod public void setSpeed(final Double key, final Float speed) { if (android.os.Build.VERSION.SDK_INT < 23) { Log.w("RNSoundModule", "setSpeed ignored due to sdk limit"); return; }

MediaPlayer player = this.playerPool.get(key);
if (player != null) {
  player.setPlaybackParams(player.getPlaybackParams().setSpeed(speed));
}

}

https://github.com/zmxv/react-native-sound/blob/253a35ca6841b8087081ec2d3565cbd2f3ea9612/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java#L355

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

trepidity avatar Mar 10 '18 17:03 trepidity

@esutton any update on this issue, we are also facing this issue on android version greater than 4, like android 10,6 and 9.

saurabhkanswal avatar Jul 10 '22 21:07 saurabhkanswal