我有这个功能,使用audioplayer plugin在Flutter内部播放声音 .
play(int soundFrequency) async {
final result = await audioPlayer.play("urltosound.wav");
}
它工作正常 . 但现在我希望能够连续播放多个声音 . 好像我搞砸了未来 . 我尝试过这种方法,非常肮脏和丑陋,但我只想弄清楚事情:
playRandomSequence() async {
final result = audioPlayer.play("urltosound.wav").then(play2(pickRandomSoundFrequency()));
}
play2(int soundFrequency) async {
final result = audioPlayer.play("urltosound.wav");
}
基本上,只要第一个未来结束,我就用.then()方法调用下一个 .
我得到的是这个错误:
type '_Future' is not a subtype of type '(dynamic) => dynamic' of 'f' where _Future is from dart:async
我怎样才能解决这个问题?
谢谢
1 回答
.then()
的参数类型错误 . 尝试:您需要传递一个要调用的函数,而不是在构造
then
的参数时调用该函数 .