From 78674d35b90eb34ba047c37b7d48be91559e439c Mon Sep 17 00:00:00 2001 From: faiface Date: Wed, 12 Jul 2017 00:05:42 +0200 Subject: [PATCH] add StreamSeeker, StreamCloser and StreamSeekCloser interfaces --- audio/interface.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/audio/interface.go b/audio/interface.go index 4b6d97b..ad05342 100644 --- a/audio/interface.go +++ b/audio/interface.go @@ -1,5 +1,7 @@ package audio +import "time" + // SampleRate is the number of audio samples a Streamer should produce per one second of audio. // // This value should be set at most once before using audio package. It is safe to assume that this @@ -48,6 +50,43 @@ type Streamer interface { Err() error } +// StreamSeeker is a finite duration Streamer which supports seeking to an arbitrary position. +type StreamSeeker interface { + Streamer + + // Duration returns the total duration of the Streamer. + Duration() time.Duration + + // Position returns the current position of the Streamer. This value is between 0 and the + // total duration. + Position() time.Duration + + // Seek sets the position of the Streamer to the provided value. + // + // If an error occurs during seeking, the position remains unchanged. This error will not be + // returned through the Streamer's Err method. + Seek(d time.Duration) error +} + +// StreamCloser is a Streamer streaming from a resource which needs to be released, such as a file +// or a network connection. +type StreamCloser interface { + Streamer + + // Close closes the Streamer and releases it's resources. Streamer will no longer stream any + // samples. + Close() error +} + +// StreamSeekCloser is a union of StreamSeeker and StreamCloser. +type StreamSeekCloser interface { + Streamer + Duration() time.Duration + Position() time.Duration + Seek(d time.Duration) error + Close() error +} + // StreamerFunc is a Streamer created by simply wrapping a streaming function (usually a closure, // which encloses a time tracking variable). This sometimes simplifies creating new streamers. //