Gapless playback doesn’t work with FLAC, but only on the first song for the first playthrough.

huangapple go评论67阅读模式
英文:

just_audio/audio_service: Gapless playback doesn't work with FLAC, but only on the first song for the first playthrough

问题

抱歉提出不够完美的问题,但我已经尝试了所有的选项,不知道还能做什么。

在iOS上播放来自文件的FLAC文件时,从第1首歌到第2首歌的过渡会有约100毫秒的卡顿,即使从ConcatenatingAudioSource播放也是如此。我无法通过修改audio_service播放列表示例来重现这个问题,跳回并再次听过过渡是正常的(无缝)。

通过HTTP播放相同的歌曲是无缝的。

我没有最小的示例,但这里有一些链接到我的代码:

如果没有明确的答案也没关系(我没有一个好的示例,这在某种程度上阻碍了解决问题)。我只想知道是否有可能在这里做些什么。我可能会尝试在下一首歌曲前大约5秒强制加载下一项的方法,但这是一个不好的解决方案,显然是不必要的。

英文:

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.

答案1

得分: 1

免责声明:我是一个完全的初学者,所以下面的任何内容都可能与您所问的问题完全无关。

当我在使用 ConcatenatingAudioSource 与 just_audio 播放 mp3 时,发现了一个在不同 mp3 之间出现的 1 到 2 个约100毫秒的卡顿问题。希望从以下内容中,您可以推断出解决方案。

我的应用程序基础:加载五个循环,当用户到达第五个循环的开头时,加载另外五个循环,以用户正在听的时间为重复。我的循环每个30秒,我有一个计时器来控制循环播放时的其他操作。

我的应用程序可以始终无缺地播放前五个循环。然而,每个额外的循环之间都有约100毫秒的卡顿。

我采取了两个措施来解决问题:

  1. 停止尝试将多个循环附加到播放列表
  2. 停止尝试在计时器的第一秒加载

以下是我的代码片段。

int timerCounter = 0;
late Timer timeControl;

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

      // 下面这行被注释掉的代码在 timerCounter == 1 时会导致卡顿
      // timerCounter == 1 ? addMultipleLoops(storedPlaylist) : null;

      // 我用以下方式解决了卡顿问题
      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 {
  // 我的循环名称是从1开始的数字(例如:1.mp3, 2.mp3, 3.mp3...等等)
  // 在索引位置为0时,将1添加到indexPosition将引用第一个循环(1.mp3)。
  int loop = indexPosition + 1;
  if (indexPosition == 4) {
    loop = 1;
  }

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

希望这些信息对您有所帮助。如果您有任何进一步的问题,请随时提出。

英文:

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 &lt;= 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&lt;int&gt; storedPlaylist) {

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

      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(&#39;${directory}/${loop}.mp3&#39;));
      }
    }

答案2

得分: 0

我的问题已通过切换到feature/treadmill分支的方式得到解决。目前还不适用于生产环境,但希望很快发布。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月28日 07:59:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349468.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定