ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Playing Audio with Fade In/Out effect

Open aareeph opened this issue 2 years ago • 2 comments

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

aareeph avatar Oct 19 '22 06:10 aareeph

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.

tonihei avatar Oct 21 '22 08:10 tonihei

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)

Abcfinite avatar Nov 19 '23 10:11 Abcfinite