ExoPlayer
ExoPlayer copied to clipboard
Playing Audio with Fade In/Out effect
Previously I was using the Timer() thread to create a Volume Fade In and Fade Out effects while playing the audio and setting up the volume in it. After upgrading to the latest version of ExoPlayer now I am getting the following error message:
java.lang.IllegalStateException: Player is accessed on the wrong thread. Current thread: 'Timer-0' Expected thread: 'main'
I understand that ExoPlayer needs to accessed via same thread, but is there a way to create the Volume Fade In/Fade Out effect?
Thanks
Yes, that's right, your need to access the player from a single thread at all times (usually the main thread). If you get signals on another thread, you can usually send a Handler message/post to the player thread to handle them there. This has always been the case, we just didn't enforce it.
We also don't support fading effects out of the box at the moment. I can mark this as an enhancement to support such effects either via Exoplayer's audio processors or via VolumeShaper
.
it would be great to have built in function for fade in/out but meanwhile. We can do something like this :
var handler = Handler(player.applicationLooper)
handler.postDelayed({
controller.volume = 0.6f
}, 1000)