playNextAudio method
function for playing next audio
Implementation
playNextAudio(String msgID) async {
if (checkAutoPlayConditions(msgID)) {
String convKey = _audioPlayInfo!.convKey;
int convType = _audioPlayInfo!.convType;
String msgID = _audioPlayInfo!.msgID;
var messageList = getMessageList(key: convKey);
var idx = messageList.indexWhere((element) => element.msgID == msgID);
if (idx > -1) {
var leftMessageList = messageList.getRange(0, idx).toList().reversed.toList();
var nextIndex = leftMessageList.indexWhere((element) => element.elemType == MessageElemType.V2TIM_ELEM_TYPE_SOUND);
if (nextIndex > -1) {
var nextSoundMessage = leftMessageList[nextIndex];
if (nextSoundMessage.soundElem != null) {
var soundElem = nextSoundMessage.soundElem!;
late AudioPlayType type;
String p = "";
int totalSecond = soundElem.duration ?? 0;
String nextMsgId = nextSoundMessage.msgID ?? "";
if (TencentCloudChatUtils.checkString(soundElem.localUrl) != null || TencentCloudChatUtils.checkString(soundElem.path) != null) {
type = AudioPlayType.path;
if (TencentCloudChatUtils.checkString(soundElem.localUrl) != null) {
p = soundElem.localUrl!;
} else {
p = soundElem.path!;
}
} else {
type = AudioPlayType.online;
var urlRes = await TencentCloudChat.instance.chatSDKInstance.messageSDK.getMessageOnlineUrl(msgID: nextMsgId);
if (urlRes != null) {
if (urlRes.soundElem != null) {
if (TencentCloudChatUtils.checkString(urlRes.soundElem!.url) != null) {
p = urlRes.soundElem!.url!;
}
}
}
}
if (checkAutoPlayConditions(msgID) && p.isNotEmpty && totalSecond > 0 && nextMsgId.isNotEmpty) {
console(logs: "start play next audio, messageID: $nextMsgId");
await playAudio(source: AudioPlayInfo(type: type, path: p, msgID: nextMsgId, totalSecond: totalSecond, convKey: convKey, convType: convType));
}
}
}
}
}
}