我正在使用just_audio,效果很好。
但是似乎找不到快速前进或快退的方法。
答案 0 :(得分:0)
没有内置的快进或快退功能,但是您可以编写一个循环,尝试搜索currentPosition + Duration(seconds: 10)
,然后重复睡眠1秒钟。这是在audio_service示例中使用类似于以下内容的帮助器类实现的方式:
class Seeker {
/// A reference to your just_audio player
final AudioPlayer player;
final Duration positionInterval;
final Duration stepInterval;
final Duration fileDuration;
bool _running = false;
Seeker(
this.player,
this.positionInterval,
this.stepInterval,
this.fileDuration,
);
start() async {
_running = true;
while (_running) {
Duration newPosition = player.position + positionInterval;
if (newPosition < Duration.zero) newPosition = Duration.zero;
if (newPosition > fileDuration) newPosition = fileDuration;
player.seek(newPosition);
await Future.delayed(stepInterval);
}
}
stop() {
_running = false;
}
}
要通过每1秒以10秒的间隔向前跳跃来开始快进,请使用:
seeker = Seeker(player, Duration(seconds: 10),
Duration(seconds: 1), mediaItem)
..start();
并使用以下命令停止快进:
seeker.stop();
要快退,只需以负数10秒过去。
答案 1 :(得分:0)
player.seek(Duration(seconds: player.position.inSeconds - 15));
倒带 15 秒
player.seek(Duration(seconds: player.position.inSeconds + 15));
前进 15 秒'
IconButton(
icon: Icon(
Icons.replay_10,
color: Colors.white,
),
iconSize: 25,
onPressed: () async {
await player.seek(Duration(seconds: player.position.inSeconds - 15));
},
)`
player
来自 AudioPlayer player