seek(
double newValue,
) async {
audioPlayer.positionStream.listen((event) {
if (event == _audioDuration) {
print(newValue);
_saveValue = 0;
notifyListeners();
stopAll2();
recordBool(false);
// Update the icon to play button
} else {
if (audioPlayer.playing) {
// print('false');
recordBool(true);
}
}
});
if (_startPlaybackTime == 0.0) {
_startPlaybackTime = audioPlayer.duration!.inMilliseconds.toDouble();
_startDuration = audioPlayer.duration!;
_vocalDuration = vocalPlayer.duration!;
_bassDuration = bassPlayer.duration!;
_pianoDuration = pianoPlayer.duration!;
_drumDuration = drumsPlayer.duration!;
_otherDuration = otherPlayer.duration ?? const Duration();
notifyListeners();
}
// Duration background = Duration(milliseconds: newValue.round());
await Future.wait([
_audioPlayer.load(), // Load the audio player before seeking
vocalPlayer.load(),
bassPlayer.load(),
pianoPlayer.load(),
otherPlayer.load(),
drumsPlayer.load(),
]);
await vocalPlayer.seek(Duration(milliseconds: newValue.round()));
await bassPlayer.seek(Duration(milliseconds: newValue.round()));
await pianoPlayer.seek(Duration(milliseconds: newValue.round()));
await otherPlayer.seek(Duration(milliseconds: newValue.round()));
await drumsPlayer.seek(Duration(milliseconds: newValue.round()));
double dura = _vocalDuration.inMilliseconds.toDouble() - newValue;
double recordedAudioStartOffset =
newValue / _vocalDuration.inMilliseconds.toDouble();
double adjustedStartClipTime =
recordedAudioStartOffset * _startPlaybackTime;
Duration start = Duration(milliseconds: adjustedStartClipTime.toInt());
print('recordedAudioStartOffset: $recordedAudioStartOffset');
print('star ${audioDuration.inMilliseconds.toDouble()}');
print('new value ${_songDuration.inMilliseconds.toDouble()}');
print('startPlay $start');
try {
await _audioPlayer
.setClip(start:start)
.whenComplete(() async {
_isClipSet = true;
notifyListeners();
print('Acomp');
});
} on PlatformException catch (e) {
print(e);
}
notifyListeners();
}
**This is my code , the process starts when i'm recording an audio and the vocalPlayer, bassPlayer, drumPlayer, PianoPlayer, OtherPlayer play simultaneously and when i change the position of all using the slider widget and start singing (this is like a karaoke app) and then stop and i click the play button this seek method comes into effect with the newvalue containing the seeked position , the audioplayer doesn't start precisely from where the 5 players(vocalPlayer, bassPlayer, drumPlayer, pianoPlayer, OtherPlayer ) were seeked **