在我的颤振应用程序中,我试图更改列表项中文本的背景颜色以播放音频。所以每个列表项都有一个音频文件。我必须检测音频何时结束,然后相应地突出显示下一个项目并自动播放下一个音频。问题在于当前代码,第一个列表项不是随着第一个音频播放而改变背景颜色。
void playAudioNetwork(int index) async{
Playlist playlist;
List<int> durations = [6,7,5,5,7,6,18];
List<Audio> _audios = [];
for (int i =0;i<=6;i++) {
String Url= 'https://everyayah.com/data/Ayman_Sowaid_64kbps/00100${i+1}.mp3';
await audioPlayer.open(Audio.network(Url));
await Future.delayed(Duration(seconds: durations[i]), () {
getBgColor(i+1);
setState(() {
});
});
print(Url);
}
}
我尝试在音频开始之前调用第一个索引的颜色更改方法,如下所示:
void playAudioNetwork(int index) async{
Playlist playlist;
List<int> durations = [6,7,4,5,7,6,18];
List<Audio> _audios = [];
await Future.delayed(Duration(seconds: durations[0]), () {
getBgColor(0);
setState(() {
});
});
for (int i =0;i<=6;i++) {
String Url= 'https://everyayah.com/data/Ayman_Sowaid_64kbps/00100${i+1}.mp3';
await audioPlayer.open(Audio.network(Url));
await Future.delayed(Duration(seconds: durations[i]), () {
getBgColor(i+1);
setState(() {
});
});
print(Url);
}
}
现在,第一个索引确实通过正确的音频播放改变了它的背景颜色,但音频开始也被延迟了。按下播放按钮 6 秒后开始播放音频。我需要帮助如何在不延迟整个音频播放过程的情况下突出显示第一个索引?谢谢你。
Color getBgColor(int index){
highlightedIndex = index;
}
TextSpan(
text: arabic ,
style: TextStyle(
color: getTextColor(index),
backgroundColor: highlightedIndex == index ? Colors.blue: Colors.white ,
fontSize: 24.0,
fontWeight: FontWeight.w200,
fontFamily: 'uthmanitext', ),