flutter setVolume方法AudioPlayer不工作-抖动

5t7ly7z5  于 2022-12-05  发布在  Flutter
关注(0)|答案(1)|浏览(132)

音频播放器的setVolume方法不起作用。例如:当我将音量值设置为0时,它应该会静音,对吗?但尽管将音量设置为0,我仍然可以听到音量

AudioPlayer audioPlayer = AudioPlayer();

void playMusic() async {
await audioPlayer.setVolume(0); // Not working
audioPlayer.play(url); // I can still hear the volume despite setting the volume value to zero
}
btqmn9zl

btqmn9zl1#

final audioPlayer = AudioPlayer();
bool isPlaying = false;
double _value = 0.0;
String url = '';
@override
void initState() {
super.initState();

audioPlayer.onPlayerStateChanged.listen((state) {
  setState(() {
    isPlaying = state == PlayerState.playing;
  });
});

audioPlayer.setVolume(_value);
}

然后,我将按滑块值更新音量值。

相关问题