Skip to content

Commit 4b279f6

Browse files
committed
Auto-seek to the last timecode upon reopening
1 parent 46e2295 commit 4b279f6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

sound/sound.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package sound
1515

1616
import (
1717
"fmt"
18+
"math"
1819
"os/exec"
1920
"time"
2021

@@ -189,7 +190,7 @@ func (p *Player) procWatcher() {
189190
p.hndl.Post(ev.RequestShutdown)
190191
}
191192

192-
func (p *Player) load(filename string) {
193+
func (p *Player) load(filename string, starttime int) {
193194
if p.proc == nil || p.ctrl == nil {
194195
p.start()
195196
}
@@ -199,10 +200,28 @@ func (p *Player) load(filename string) {
199200
// Wait for track to load
200201
for loaded := ""; loaded != "\""+filename+"\""; loaded, _ = p.ctrl.Path() {
201202
}
203+
for {
204+
pos, _ := p.ctrl.PercentPosition()
205+
if pos != 0 {
206+
break
207+
}
208+
}
209+
210+
p.ctrl.Seek(starttime, mpv.SeekModeAbsolute)
202211
}
203212

204213
func (p *Player) play(q *data.QueueItem) {
205-
p.load(q.Path)
214+
_, s, err := data.Stamps.Stat(q.Path)
215+
if err != nil {
216+
tmp := uint64(0)
217+
s = &tmp
218+
}
219+
if *s > uint64(math.MaxInt) {
220+
tmp := uint64(math.MaxInt)
221+
s = &tmp
222+
}
223+
224+
p.load(q.Path, int(*s))
206225

207226
if q.State != data.StatePending {
208227
Plr.Now = q

0 commit comments

Comments
 (0)