Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Cross Fade #237

Open
Ge082 opened this issue May 20, 2022 · 25 comments
Open

[Feature Request] Cross Fade #237

Ge082 opened this issue May 20, 2022 · 25 comments

Comments

@Ge082
Copy link

Ge082 commented May 20, 2022

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
Copy link

B16WLL commented May 23, 2022

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
Copy link
Contributor

rom4nik commented May 25, 2022

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
Copy link

waynepaulward commented Jun 19, 2022

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
Copy link

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
Copy link

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

@jmshrv
Copy link
Owner

jmshrv commented Nov 18, 2022

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

@BloodyIron
Copy link

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

@waynepaulward
Copy link

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
Copy link

@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
Copy link
Owner

jmshrv commented Mar 1, 2023

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

@BobcatNoah
Copy link
Contributor

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
Copy link
Collaborator

@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
Copy link
Contributor

BobcatNoah commented Oct 9, 2023

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

@Chaphasilor
Copy link
Collaborator

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
Copy link
Contributor

BobcatNoah commented Oct 11, 2023

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
Copy link
Owner

jmshrv commented Oct 12, 2023

hmm, are you on iOS or Android?

@BobcatNoah
Copy link
Contributor

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

@BobcatNoah
Copy link
Contributor

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
Copy link
Collaborator

Nice! How does it sound?

@BobcatNoah
Copy link
Contributor

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
Copy link
Collaborator

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
Copy link
Contributor

BobcatNoah commented Oct 30, 2023

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.

2023-10-30.17-59-44.mp4

@Chaphasilor
Copy link
Collaborator

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

@Chaphasilor Chaphasilor linked a pull request Jan 25, 2024 that will close this issue
@drazil100
Copy link

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

@BobcatNoah
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants