playNextVideo method
dynamic
playNextVideo()
function for playing next video
Implementation
playNextVideo() async {
Future.delayed(const Duration(seconds: 1), () async {
if (_audioPlayInfo != null && _currentPlayAudioInfo != null) {
String convKey = _audioPlayInfo!.convKey;
int convType = _audioPlayInfo!.convType;
String msgID = _audioPlayInfo!.msgID;
_audioPlayInfo = null;
_currentPlayAudioInfo = null;
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: msgID);
if (urlRes != null) {
if (urlRes.soundElem != null) {
if (TencentCloudChatUtils.checkString(urlRes.soundElem!.url) != null) {
p = urlRes.soundElem!.url!;
}
}
}
}
if (p.isNotEmpty && totalSecond > 0 && nextMsgId.isNotEmpty) {
console(logs: "start play next video");
await playAudio(source: AudioPlayInfo(type: type, path: p, msgID: nextMsgId, totalSecond: totalSecond, convKey: convKey, convType: convType));
}
}
}
}
}
});
}