diff --git a/modules/demux/adaptive/playlist/SegmentTemplate.cpp b/modules/demux/adaptive/playlist/SegmentTemplate.cpp
index 2bef4b3d40e75390bcf8683a39c3d9a9b5f9f7d9..173264000bd77382830dbe8489d0b9c8804c046c 100644
--- a/modules/demux/adaptive/playlist/SegmentTemplate.cpp
+++ b/modules/demux/adaptive/playlist/SegmentTemplate.cpp
@@ -144,7 +144,7 @@ vlc_tick_t SegmentTemplate::getMinAheadTime(uint64_t number) const
 Segment * SegmentTemplate::getMediaSegment(uint64_t number) const
 {
     const SegmentTimeline *tl = inheritSegmentTimeline();
-    if(tl == nullptr || tl->maxElementNumber() > number)
+    if(tl == nullptr || (tl->maxElementNumber() >= number && tl->minElementNumber() <= number))
         return virtualsegment;
     return nullptr;
 }