From 86d01d3eff3e77d50051811e970c3fe93abcf145 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Mon, 6 Jul 2020 16:17:08 +0200 Subject: [PATCH] Start to sketch out a Playlist interface/struct --- main.go | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index e7e34d0..ca4416d 100644 --- a/main.go +++ b/main.go @@ -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: