Start to sketch out a Playlist interface/struct

This commit is contained in:
Rob Watson 2020-07-06 16:17:08 +02:00
parent 17ff26daf3
commit 86d01d3eff
1 changed files with 32 additions and 6 deletions

38
main.go
View File

@ -86,6 +86,7 @@ func (s *MP3HTTPSegmenter) Segment(r io.Reader) (chan *Segment, error) {
}
if s == nil {
// TODO what is a good initial capacity?
s = newSegment(DefaultTargetDuration, 1024)
}
@ -110,13 +111,38 @@ func newMP3HTTPSegmenter() *MP3HTTPSegmenter {
return &MP3HTTPSegmenter{}
}
// TODO
type Playlist interface {
// These could be moved to an interface?
Duration() time.Duration
TargetDuration() time.Duration
}
// A Segmenter class which allows the passing in of a Reader
// i.e.
// Segment(r io.Reader) (chan *Segment, error)
// This will create an mp3.NewDecoder(r) and store the returned decoder.
// As the Reader is read, the Segmenter will publish a stream of SegmentEvents
type MediaPlaylist struct {
Segments []*Segment
}
func newMediaPlaylist() *MediaPlaylist {
return &MediaPlaylist{
Segments: make([]*Segment, 0, 10),
}
}
func (p *MediaPlaylist) Duration() time.Duration {
var t time.Duration
for _, s := range p.Segments {
t += s.Duration()
}
return t
}
func (p *MediaPlaylist) Run() error {
for {
// TODO block here and listen to the channel of incoming segments.
// As the reader is Read and segments are produced, update the Playlist
// struct and possibly notify consumers.
// What would actually be a useful API and/or Go best practices?
}
}
func main() {
// TODO accept some flags with: