Move the stuff to the widget, not the player
This commit is contained in:
parent
3a8807101e
commit
84f7cb4069
|
@ -41,16 +41,15 @@ const (
|
||||||
// player holds all the data
|
// player holds all the data
|
||||||
// necessary for playing video.
|
// necessary for playing video.
|
||||||
type player struct {
|
type player struct {
|
||||||
pix *image.NRGBA
|
pix *image.NRGBA
|
||||||
ticker <-chan time.Time
|
ticker <-chan time.Time
|
||||||
errs <-chan error
|
errs <-chan error
|
||||||
frameBuffer <-chan *image.RGBA
|
frameBuffer <-chan *image.RGBA
|
||||||
audioBuffer <-chan [2]float64
|
audioBuffer <-chan [2]float64
|
||||||
last time.Time
|
last time.Time
|
||||||
fps int
|
fps int
|
||||||
paused bool
|
paused bool
|
||||||
frameCount int64
|
frameCount int64
|
||||||
audioProcessor func([2]float64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// readVideoAndAudio reads video and audio frames
|
// readVideoAndAudio reads video and audio frames
|
||||||
|
@ -179,18 +178,6 @@ func (p *player) readVideoAndAudio(media *reisen.Media) (<-chan *image.RGBA, <-c
|
||||||
return frameBuffer, sampleBuffer, errs, nil
|
return frameBuffer, sampleBuffer, errs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) SetAudioProcessorFunc(f func(data [2]float64)) {
|
|
||||||
p.audioProcessor = f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *player) processAudioFrame(data [2]float64) {
|
|
||||||
if p.audioProcessor != nil {
|
|
||||||
p.audioProcessor(data)
|
|
||||||
} else {
|
|
||||||
_ = data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starts reading samples and frames
|
// Starts reading samples and frames
|
||||||
// of the media file.
|
// of the media file.
|
||||||
func (p *player) open(fname string) error {
|
func (p *player) open(fname string) error {
|
||||||
|
@ -271,6 +258,7 @@ type BufferedVidPlayback struct {
|
||||||
allFrames []image.RGBA
|
allFrames []image.RGBA
|
||||||
bufferFilling bool
|
bufferFilling bool
|
||||||
paused bool
|
paused bool
|
||||||
|
audioProcessor func([2]float64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBufferedVidPlayback() *BufferedVidPlayback {
|
func NewBufferedVidPlayback() *BufferedVidPlayback {
|
||||||
|
@ -309,7 +297,7 @@ func (w *BufferedVidPlayback) Play() {
|
||||||
w.fpsTimer.Reset(frameDuration)
|
w.fpsTimer.Reset(frameDuration)
|
||||||
go func(p player) {
|
go func(p player) {
|
||||||
for {
|
for {
|
||||||
p.processAudioFrame(<-w.playerStruct.audioBuffer)
|
w.processAudioFrame(<-w.playerStruct.audioBuffer)
|
||||||
}
|
}
|
||||||
}(w.playerStruct)
|
}(w.playerStruct)
|
||||||
w.FillBuffer()
|
w.FillBuffer()
|
||||||
|
@ -373,6 +361,18 @@ func (w *BufferedVidPlayback) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return newBufferedVidPlaybackRenderer(w)
|
return newBufferedVidPlaybackRenderer(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *BufferedVidPlayback) SetAudioProcessorFunc(f func(data [2]float64)) {
|
||||||
|
w.audioProcessor = f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *BufferedVidPlayback) processAudioFrame(data [2]float64) {
|
||||||
|
if w.audioProcessor != nil {
|
||||||
|
w.audioProcessor(data)
|
||||||
|
} else {
|
||||||
|
_ = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type bufferedVidPlaybackRenderer struct {
|
type bufferedVidPlaybackRenderer struct {
|
||||||
bufferedVidPlayback *BufferedVidPlayback
|
bufferedVidPlayback *BufferedVidPlayback
|
||||||
currentframe *canvas.Raster
|
currentframe *canvas.Raster
|
||||||
|
|
Loading…
Reference in New Issue