From 6aa61f970d84a7a228c48726e65e55afcaefd266 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Sun, 8 Oct 2023 23:11:10 +0800 Subject: [PATCH] try to play from begin if current video is removed --- mdkvideo.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mdkvideo.cpp b/mdkvideo.cpp index acedfc1..3edcfe9 100755 --- a/mdkvideo.cpp +++ b/mdkvideo.cpp @@ -140,21 +140,22 @@ class mdkVideoSource { loop_ = loop; urls_ = urls; player_.setNextMedia(nullptr); - if (urls_.empty()) + if (urls_.empty()) { + player_.set(State::Stopped); return; + } string next; auto now = player_.url(); - if (!now) { + auto it = now ? find(urls_.cbegin(), urls_.cend(), now) : urls_.cend(); + if (!now || it == urls_.cend()) { next_it_ = urls_.cbegin(); if (++next_it_ == urls_.cend() && loop_) next_it_ = urls_.cbegin(); play(urls_.front().data()); return; } - auto it = find(urls_.cbegin(), urls_.cend(), now); - if (it != urls_.cend()) - next_it_ = ++it; - if (it == urls_.cend()) { + next_it_ = ++it; + if (it == urls_.cend()) { if (!loop_) { player_.setNextMedia(nullptr); return;