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

Cross fade #237 #523

Closed
wants to merge 3 commits into from
Closed

Cross fade #237 #523

wants to merge 3 commits into from

Conversation

BobcatNoah
Copy link
Contributor

@BobcatNoah BobcatNoah commented Nov 1, 2023

This PR is work in progress and will implement cross fade #237 between songs. The code is not complete because I want someone to review it before I move forward and there is a major issue I need help with.

I don't have a video example right now, but the issue is that the cross fade is being paused before the seeking is finished. This causes a noticeable gap on slower devices or when the device is connected to something like a car stereo. The expected behavior is that it waits until the seeking is finished before pausing. I suspect this is being caused by a delay between when the seek function finishes (thus returning and letting the code continue) and when the song actually starts playing again.

_player.currentIndexStream.listen((event) async {
        if (_player.processingState == ProcessingState.ready) {
          //fadeIsReady = false;
          _player.setVolume(1);
          if (event != null && nextItem == _getQueueItem(_player.currentIndex?? 0)) {
            await Future.delayed(const Duration(milliseconds: 1));
            //final test = Stopwatch();
            //test.start();
            await _player.seek(_crossFadePlayer.position);
            await Future.delayed(Duration(milliseconds: 15));
            _crossFadePlayer.pause();
            //test.stop();
            //_audioServiceBackgroundTaskLogger.info(test.elapsedMilliseconds);
            //finishedSwitchingSong = true;
          }
        }
      });

Below is a video of expected behavior. This example isn't perfect though due to the issue.

RPReplay_Final1698882594.MP4

@BobcatNoah BobcatNoah marked this pull request as draft November 1, 2023 23:57
@jmshrv
Copy link
Owner

jmshrv commented Nov 2, 2023

I believe @Chaphasilor was working on this, they may be able to help :)

@Chaphasilor
Copy link
Collaborator

I was not, but my suggestion would be to pause the crossfading player a few seconds later. Maybe fade the volume down again until the actual track is playing?
Otherwise, if the timing still isn't perfect, it might be necessary to create two full-blown player instances and manage them somehow, which seems like a nightmare...

@BobcatNoah
Copy link
Contributor Author

The timing isn't perfect and I can't think of any way to account for the latency added by seeking. Fading the volume down may work, but I'm not sure how well. I have no way knowing when the track is actually playing after the seek and just adding a few seconds would sound bad on devices that seek really fast.
I don't think crossfade is worth creating two full-blown player instances. It definitely would be a nightmare.

@Chaphasilor Chaphasilor linked an issue Jan 25, 2024 that may be closed by this pull request
@BobcatNoah BobcatNoah closed this Jan 27, 2024
@Chaphasilor
Copy link
Collaborator

Hi @BobcatNoah, sorry that I never managed to take a closer look.
I was planning to do that once the initial beta release is done. Is there any particular reason why you closed the PR? :)

@BobcatNoah
Copy link
Contributor Author

From my testing, I noticed that different devices had different delays for when you call the play method and when it actually starts playing. This meant I can never perfectly sync up the transition between the songs. On my phone, it might sound fine but on a car stereo, there might be a noticeable delay.

@BobcatNoah
Copy link
Contributor Author

Alternatively, I could try the original method of having two separate players in which Finamp would alternate between the two.

image

@Chaphasilor
Copy link
Collaborator

Hmm, okay. Maybe just_audio will get cross-fase support at some point, but that might be a while. The two player approach would be the best solution for cross-fading, but I don't think it would play nicely with the queue and the player itself.
But you're welcome to give it a try, if you feel like it!

@BobcatNoah
Copy link
Contributor Author

I didn't even consider the queue being a problem. I guess I'll have to put this on hold until just_audio add crossfade.

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 this pull request may close these issues.

[Feature Request] Cross Fade
3 participants