androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.57k stars 373 forks source link

Feature request (fade and crossfade audio)) #2

Open prime-zs1 opened 2 years ago

prime-zs1 commented 2 years ago

It would be extremely helpful to provide fade in/FadeOut and crossfade audio feature. Since current implementation of media3 supports only one Exoplayer, hence crossFade seems not possible. Since this is the first release, it would be easy to fix it here and add the said feature.

icbaker commented 2 years ago

This looks like a duplicate of https://github.com/google/ExoPlayer/issues/3438.

If that issue is fixed it will be fixed in both exoplayer2 and media3. However we don't have current plans to look at this.

I'll leave both issues open for now, we may in future de-dupe them.

Tolriq commented 2 months ago

Since this is still the most requested feature I get I wanted to try to provide at least fade in / out if not real crossfade, and wanted to use volumeshaper to do it right.

But I can't seem to find a way to properly access the actual audioTrack to apply it. The only solution I can imagine would be to duplicate DefaultAudioSink to make it open to be able to extend it.

Is there something obvious I'm missing?

Samrobbo commented 2 months ago

You may be able to implement this through an AudioProcessor.

For fade-out, you could have an internal queue of decoded audio with a size that matches your preferred fade out duration. Once end of stream is signal to the processor, it can scale down the audio it has.

For fade-in, this might be more difficult, because AudioProcessor does not have information about whether a flush was related to a seek or a new item in the playlist.

Tolriq commented 2 months ago

Actually for fade in I can manage via the audiosink configure to know a new media starts I do that for the replaygain to pass down the metadata.

But the issue is also about how to know the durations and everything from the data the processor have, it's a lot simpler with volumeshaper and sending an event via sendMessage at proper timings.

For the fade out I also have no idea how to calculate the buffer duration and if the user want 5 seconds this means audio is delayed by 5 seconds no?

Tolriq commented 1 month ago

So I've made some tests and audioprocessor for fade out can't work for anything else than real normal end of track and pre buffering.

If you want to fade out on pause or when skipping next the processor have already processed the data and is a couple of second later and there's no way to anticipate that.

So the only way to do things in real time when needed and do it properly is the volumeShaper that needs access to the audioTrack to be created.

Since there's already an onAudioTrackInitialized does it make sense to have an official way to access the audioTrack too to be able to call audioTrack.createVolumeShaper() ? (Asking @tonihei too)