From 4c651736048235b53fb59c8696f86ca993df99e8 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 30 Jan 2020 11:21:56 +1030 Subject: [PATCH] device/file: implement IsRunning method for file --- device/file/file.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/device/file/file.go b/device/file/file.go index 299a45e6..d068ace6 100644 --- a/device/file/file.go +++ b/device/file/file.go @@ -36,8 +36,9 @@ import ( // AVFile is an implementation of the AVDevice interface for a file containg // audio or video data. type AVFile struct { - f io.ReadCloser - cfg config.Config + f io.ReadCloser + cfg config.Config + isRunning bool } // NewAVFile returns a new AVFile. @@ -62,11 +63,19 @@ func (m *AVFile) Start() error { if err != nil { return fmt.Errorf("could not open media file: %w", err) } + m.isRunning = true return nil } // Stop will close the file such that any further reads will fail. -func (m *AVFile) Stop() error { return m.f.Close() } +func (m *AVFile) Stop() error { + err := m.f.Close() + if err == nil { + m.isRunning = false + return nil + } + return err +} // Read implements io.Reader. If start has not been called, or Start has been // called and Stop has since been called, an error is returned. @@ -79,6 +88,5 @@ func (m *AVFile) Read(p []byte) (int, error) { // IsRunning is used to determine if the AVFile device is running. func (m *AVFile) IsRunning() bool { - panic("not implemented") - return false + return m.f != nil && m.isRunning }