Improve seek handling for embedded playback
This commit is contained in:
parent
2a677a7fe0
commit
b7361f6528
65
main.go
65
main.go
|
|
@ -1137,25 +1137,24 @@ func moduleColor(id string) color.Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
type playSession struct {
|
type playSession struct {
|
||||||
path string
|
path string
|
||||||
fps float64
|
fps float64
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
targetW int
|
targetW int
|
||||||
targetH int
|
targetH int
|
||||||
volume float64
|
volume float64
|
||||||
muted bool
|
muted bool
|
||||||
paused bool
|
paused bool
|
||||||
current float64
|
current float64
|
||||||
seekTimer *time.Timer
|
stop chan struct{}
|
||||||
stop chan struct{}
|
done chan struct{}
|
||||||
done chan struct{}
|
prog func(float64)
|
||||||
prog func(float64)
|
img *canvas.Image
|
||||||
img *canvas.Image
|
mu sync.Mutex
|
||||||
mu sync.Mutex
|
videoCmd *exec.Cmd
|
||||||
videoCmd *exec.Cmd
|
audioCmd *exec.Cmd
|
||||||
audioCmd *exec.Cmd
|
frameN int
|
||||||
frameN int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var audioCtxGlobal struct {
|
var audioCtxGlobal struct {
|
||||||
|
|
@ -1215,21 +1214,25 @@ func (p *playSession) Pause() {
|
||||||
func (p *playSession) Seek(offset float64) {
|
func (p *playSession) Seek(offset float64) {
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
defer p.mu.Unlock()
|
||||||
p.current = offset
|
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
p.current = 0
|
offset = 0
|
||||||
}
|
|
||||||
if p.seekTimer != nil {
|
|
||||||
p.seekTimer.Stop()
|
|
||||||
}
|
}
|
||||||
paused := p.paused
|
paused := p.paused
|
||||||
p.seekTimer = time.AfterFunc(90*time.Millisecond, func() {
|
p.current = offset
|
||||||
p.mu.Lock()
|
p.stopLocked()
|
||||||
defer p.mu.Unlock()
|
p.startLocked(p.current)
|
||||||
p.stopLocked()
|
p.paused = paused
|
||||||
p.startLocked(p.current)
|
if p.paused {
|
||||||
p.paused = paused
|
// Ensure loops honor paused right after restart.
|
||||||
})
|
time.AfterFunc(30*time.Millisecond, func() {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
p.paused = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if p.prog != nil {
|
||||||
|
p.prog(p.current)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playSession) SetVolume(v float64) {
|
func (p *playSession) SetVolume(v float64) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user