device/file: implement IsRunning method for file

This commit is contained in:
Scott 2020-01-30 11:21:56 +10:30
parent 5c5672486e
commit 4c65173604
1 changed files with 13 additions and 5 deletions

View File

@ -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
}