mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-30 13:48:50 +08:00
refactor
This commit is contained in:
parent
c86a4965d5
commit
ecf5ed628c
43
player.go
43
player.go
@ -171,8 +171,7 @@ func (p *Player) Run() {
|
|||||||
p.playingBar.NewProgress(song.name, int(p.length.Seconds()), 100)
|
p.playingBar.NewProgress(song.name, int(p.length.Seconds()), 100)
|
||||||
p.playingBar.Run()
|
p.playingBar.Run()
|
||||||
|
|
||||||
go func() {
|
// is used to send progress
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
next:
|
next:
|
||||||
@ -182,30 +181,6 @@ func (p *Player) Run() {
|
|||||||
case <-p.isSkipped:
|
case <-p.isSkipped:
|
||||||
break next
|
break next
|
||||||
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
// stop progress bar from progressing when paused
|
|
||||||
if !p.IsRunning {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
i++
|
|
||||||
p.playingBar.progress <- 1
|
|
||||||
|
|
||||||
|
|
||||||
if i > p.playingBar.full {
|
|
||||||
break next
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}()
|
|
||||||
|
|
||||||
next:
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-done:
|
case <-done:
|
||||||
close(done)
|
close(done)
|
||||||
p.position = 0
|
p.position = 0
|
||||||
@ -218,15 +193,31 @@ next:
|
|||||||
go p.Run()
|
go p.Run()
|
||||||
}
|
}
|
||||||
break next
|
break next
|
||||||
|
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
|
// stop progress bar from progressing when paused
|
||||||
|
if !p.IsRunning {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
i++
|
||||||
|
p.playingBar.progress <- 1
|
||||||
|
|
||||||
speaker.Lock()
|
speaker.Lock()
|
||||||
p.position = position()
|
p.position = position()
|
||||||
speaker.Unlock()
|
speaker.Unlock()
|
||||||
|
|
||||||
|
if i > p.playingBar.full {
|
||||||
|
break next
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Player) Pause() {
|
func (p *Player) Pause() {
|
||||||
speaker.Lock()
|
speaker.Lock()
|
||||||
p.ctrl.Paused = true
|
p.ctrl.Paused = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user