jmshrv / finamp

A Jellyfin music client for mobile
Mozilla Public License 2.0
1.96k stars 128 forks source link

[Feature Request] Cross Fade #237

Open Ge082 opened 2 years ago

Ge082 commented 2 years ago

What I like about PlexAmp is that once a song end by itself, there is a crossfade (Which they call "Sweet Fade) so the transition between the current song and the next song is smooth, it's very effective on Live albums because it eliminates the micro moment where there is silence that is there when the next song loads Would be cool to have the same feature

B16WLL commented 2 years ago

Or (if it's possible) pre-cache the opening few seconds of the next track in the queue, and implement a capless playback option for live/mixed albums.

rom4nik commented 2 years ago

Isn't the playback gapless already? I've listened to some live albums and always got smooth transition between tracks without any pauses (unless the artists put them in, that is).

waynepaulward commented 2 years ago

It would be great if there was a smooth fade between tracks I suppose it would have to cache tracks when you start to play the album so it can cache it and can start by playing the next track - is this a feature that will be added …

drazil100 commented 2 years ago

Playback is seamless for downloaded songs. There is a delay only for streamed songs. If you have albums that aren't supposed to have a gap between the tracks I would try downloading those albums.

waynepaulward commented 2 years ago

I should have explained this better I mean like a cross fade option so the songs fade together smoothly

jmshrv commented 1 year ago

This isn't implemented in just_audio due to platform support (https://github.com/ryanheise/just_audio/issues/815), it may be possible once I get around to the new player backend (#177)

BloodyIron commented 1 year ago

I too am interested in this for streaming, but gapless does seem to work in my brief testing with downloaded content.

waynepaulward commented 1 year ago

They use this feature on a few open source apps ie play sub and avsub and it works well they are open source and may help

ryanwwest commented 1 year ago

@BloodyIron Do you know if gapless audio worked with downloaded content when not in offline mode? I'm guessing Finamp is smart enough to always use the downloaded/cached version and so the seamless audio would apply, but unsure.

jmshrv commented 1 year ago

Yeah Finamp always defaults to downloaded content when it's available

BobcatNoah commented 1 year ago

Would it be possible to implement cross fade by creating two instances of the music player (It seems like it may be possible)? I'd be happy to look into it if it's not too impractical.

Chaphasilor commented 1 year ago

@BobcatNoah yes, that was the approach suggested by Ryan Heise over in the just_audio issue. However, I'm not sure how well thing would work, it could severely complicate things regarding pre-caching and queue handling. We would have to split the ConcatenatingAudioSource into two sources, one for even and one for odd indices. But this would result in parallel pre-caching, which is less efficient data and memory usage-wise.
I'm not sure if it's worth the tradeoff...

BobcatNoah commented 1 year ago

Does Finamp cache the entire queue, not just the next song? Well, that's unfortunate. It'd be great to have this feature.

Chaphasilor commented 1 year ago

Not the entire queue, just a certain duration in seconds. You can configure it in the "Audio Service" settings.

I mean, you can try to implement it, maybe it works better than expected. It's just that just_audio and audio_service tend to be rather inflexible, and in my opinion reliable playback is more important than nice transitions. If you can make it work though, why not? :)

BobcatNoah commented 1 year ago

I have an idea. It's crazy, but it might work and "should" be easy to implement.

For this example I’ll just use a crossfade of 4 seconds. So, 4 seconds before the first song ends, you start playing the first 4 seconds of the second song. Once those 4 seconds are over, meaning the first song is over, you skip 4 seconds into the second song. If this can be done smoothly and the next song isn’t buffering, it should sound seamless.

I started implementing this as an experiment, but I’m running into an issue. For some reason the crossfade audio doesn’t start playing until the first song ends, even if I play() it before the first song ends. Before you ask, I am using an additional AudioPlayer just for the crossfade.

jmshrv commented 1 year ago

hmm, are you on iOS or Android?

BobcatNoah commented 1 year ago

iOS simulator. Also, if you want to see my code, I could push it to my fork.

BobcatNoah commented 1 year ago

I took a break from coding and I think it was just an issue with my code. I sort of fixed it, now it's just playing at the end and the beginning of the song.

Chaphasilor commented 1 year ago

Nice! How does it sound?

BobcatNoah commented 1 year ago

It's not quite working yet because I'm running into an issue with seeking. I want the player to seek x amount of seconds into the next song after the end of each song. I initially tried the code below in order to seek every time the current song changes, but I get this error. Unhandled Exception: Bad state: Cannot fire new event. Controller is already firing an event

_player.currentIndexStream.listen((event) async {
    await seek(crossFadeLength);
});

Do you have any ideas of how to achieve this seeking effect (or fix the error, but there is probably a better way to do the seeking)?

Chaphasilor commented 1 year ago

You might want to only do the seeking if the index actually changed, because the event is fired more often. And to get started, maybe a short delay fixes the error? Just to see if it works at all...

BobcatNoah commented 1 year ago

This is the best I could get it to sound. I'll probably send a better example video later because I was skipping around the song in this video.

https://github.com/jmshrv/finamp/assets/84159993/9d6e70eb-58e2-4627-81d7-9b8c50be051f

Chaphasilor commented 1 year ago

Awesome! Just open a PR when you're ready and I'll check it out!

drazil100 commented 9 months ago

Is cross fade going to be optional? I prefer the current functionality but I support giving additional functionality to those who want crossfade.

BobcatNoah commented 9 months ago

Yes, it would be optional. However, I am no longer working on the feature.