Closed aideric closed 1 year ago
@aideric I think that setting Player to Low Latency mode will resolve this issue for you. It doesn't seem that the MediaPlayer supports variable playback rates.
player.setPlayerMode(PlayerMode.LowLatency)
@aideric are you interested in working on a fix? We are currently on our capacities 😅
I'm having the same issue in android 5.1 any update please?
Checklist
Current bug behaviour
Unable to set source and play with audioPlayer (PlayerMode mediaPlayer) error throw on configAndPrepare in WrappedPlayer https://github.com/bluefireteam/audioplayers/blob/414d94da9b0de91bd0928af3468435cfc589e6f0/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt#L306-L307
Expected behaviour
Able to play sound and no error throw in the init part. Error should throw when the user use the setRate function in api < 23.
Steps to reproduce
Logs
Full Logs
``` Unexpected error! java.lang.IllegalStateException: Changing the playback rate is only available for Android M/23+ or using LOW_LATENCY mode. at xyz.luan.audioplayers.player.MediaPlayerPlayer.setRate(MediaPlayerPlayer.kt:45) at xyz.luan.audioplayers.player.WrappedPlayer.configAndPrepare(WrappedPlayer.kt:309) at xyz.luan.audioplayers.player.WrappedPlayer.setSource(WrappedPlayer.kt:32) at xyz.luan.audioplayers.AudioplayersPlugin.handler(AudioplayersPlugin.kt:91) at xyz.luan.audioplayers.AudioplayersPlugin.access$handler(AudioplayersPlugin.kt:25) at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(AudioplayersPlugin.kt:41) at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(AudioplayersPlugin.kt:41) at xyz.luan.audioplayers.AudioplayersPlugin$safeCall$1.invokeSuspend(AudioplayersPlugin.kt:62) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Unexpected error!, Changing the playback rate is only available for Android M/23+ or using LOW_LATENCY mode., java.lang.IllegalStateException: Changing the playback rate is only available for Android M/23+ or using LOW_LATENCY mode. at xyz.luan.audioplayers.player.MediaPlayerPlayer.setRate(MediaPlayerPlayer.kt:45) at xyz.luan.audioplayers.player.WrappedPlayer.configAndPrepare(WrappedPlayer.kt:309) at xyz.luan.audioplayers.player.WrappedPlayer.setSource(WrappedPlayer.kt:32) at xyz.luan.audioplayers.AudioplayersPlugin.handler(AudioplayersPlugin.kt:91) at xyz.luan.audioplayers.AudioplayersPlugin.access$handler(AudioplayersPlugin.kt:25) at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(AudioplayersPlugin.kt:41) at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(AudioplayersPlugin.kt:41) at xyz.luan.audioplayers.AudioplayersPlugin$safeCall$1.invokeSuspend(AudioplayersPlugin.kt:62) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) , null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)Environment information
Platform 1:
debug
release
More information
we can change to configAndPrepare to
or check the sdk version in the Player.configAndPrepare before calling setRate
With the "try catch", I can play sound on android 5.1.1