Closed misssonder closed 1 year ago
Confirmed. Thank you! I'll apply your patch to the next release.
We have another problem after the patch: https://github.com/grafov/m3u8/pull/186#issuecomment-1441871073 Need more investigation.
Well, the ring buffer used inside a list of mediasegments. It was design decision made years ago :| If I were writing this today, I wouldn't repeat this decision. Hence by design the range
loop over Segments could not possible. Maybe add a new method like GetAllSegments() could be useful for the current implementation.
The method like:
func (p *MediaPlaylist) GetAllSegments() []*MediaSegment {
if p.count == 0 {
return nil
}
buf := make([]*MediaSegment, 0, p.count)
if p.head < p.tail {
for i := p.head; i < p.tail; i++ {
buf = append(buf, p.Segments[i])
}
return buf
}
for i := uint(0); i < p.tail; i++ {
buf = append(buf, p.Segments[i])
}
for i := p.head; i < p.capacity; i++ {
buf = append(buf, p.Segments[i])
}
return buf
}
Then it could be possible iterate:
for _, v := range m.GetAllSegments() {
print(v.URI)
}
The method like:
func (p *MediaPlaylist) GetAllSegments() []*MediaSegment { if p.count == 0 { return nil } buf := make([]*MediaSegment, 0, p.count) if p.head < p.tail { for i := p.head; i < p.tail; i++ { buf = append(buf, p.Segments[i]) } return buf } for i := uint(0); i < p.tail; i++ { buf = append(buf, p.Segments[i]) } for i := p.head; i < p.capacity; i++ { buf = append(buf, p.Segments[i]) } return buf }
Then it could be possible iterate:
for _, v := range m.GetAllSegments() { print(v.URI) }
OK, it also looks good.
retry this
Expected Behavior
print the url of segments
Actual Behavior
program panic
Solve
https://github.com/grafov/m3u8/pull/186