-2

apologies for the less-than-perfect question, but I've exhausted every option and I have no idea what left to do.

When playing FLACs from a file on iOS, the first transition from song 1 to 2 has a ~100ms hitch, even when playing from a ConcatenatingAudioSource. I cannot reproduce this by modifying the audio_service playlist example, and skipping back and listening to the transition again works fine (is gapless).

Playing the same songs over HTTP is gapless.

I don't have a minimal example but here are a few links to my code:

It's fine if there's no clean answer here (I don't have a good example, which kind of gets in the way of that). I'd just like to know if there's anything I could possibly do here. I might try hacking in a thing to force-load the next item ~5 seconds before the next song, but that's a bad solution which clearly isn't required.

Progman
  • 16,827
  • 6
  • 33
  • 48
UnicornsOnLSD
  • 631
  • 6
  • 24
  • Random thought - I may potentially be getting frame drops caused by switching songs (images loading and stuff like that). That's the only explanation I have, will have to investigate further – UnicornsOnLSD May 28 '23 at 00:10

2 Answers2

1

Disclaimer: I'm a complete beginner - so anything below could be completely irrelevant to the question you are asking.

I found your question when I was seeking a solution for my issue with a 1 to 2 ~100ms hitch between mp3s when playing from a ConcatenatingAudioSource with just_audio. Hopefully from the below, you can extrapolate a solution.

Basics of my app: Load five loops, when the user reached the beginning of the fifth, load five more loops, repeat for a long as the user is listening. My loops are 30 seconds long, and I have a timer that controls other actions while the loops are playing.

My app would consistently play the first five loops flawlessly. However, each of the additional loops had a ~100ms hitch in-between them.

Two things I did to resolve:

  1. Stopped trying to append multiple loops to a playing list
  2. Stopped trying to load at the first second of the timer

Here is a snippet of my code.

      int timerCounter = 0;
      late Timer timeControl;

      void loadLoops() {
        timeControl = Timer.periodic(Duration(seconds: 1), (timer)    async {
          if (timerCounter <= 30) {

            timerCounter++;

            /// next commented out line consistently causes a glitch if
            // timerCounter == 1 ? addMultipleLoops(storedPlaylist) : null;

            // my fix to get rid of glitch
            timerCounter == 6 ? addSingleLoop(loopPlayer.currentIndex! + 1): null;
            timerCounter == 31 ? timerCounter = 0: null;
          }
        });
      }

      void addMultipleLoops(List<int> storedPlaylist) {

        storedPlaylist.forEach((loop) {
          {
            loopPlaylist
                .add(AudioSource.file('${directory}/${loop}.mp3'));
          }
        });
      }

      void addSingleLoop(int indexPosition) async {
        /* my loop names are numbers starting at 1 (ex: 1.mp3, 2.mp3, 3.mp3... etc)
        ... Adding 1 to indexPosition references
        the first loop (1.mp3) when my index position is at 0.
        */

        int loop = indexPosition + 1;
        if(indexPosition == 4) {
          loop = 1;
        }

        loopPlaylist.add(AudioSource.file('${directory}/${loop}.mp3'));
      }
    }
Shane
  • 11
  • 2
0

My issue has been fixed by switching to the feature/treadmill branch of just_audio. It's not ready for production yet, but hopefully it gets released soon.

UnicornsOnLSD
  • 631
  • 6
  • 24