In Playlist embed a sync.Mutex instead.
This commit is contained in:
parent
6ce4700420
commit
10bc3a3785
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// Playlist holds a list of paths to a song files.
|
// Playlist holds a list of paths to a song files.
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
mut sync.Mutex
|
sync.Mutex
|
||||||
filePath string
|
filePath string
|
||||||
playlist []string
|
playlist []string
|
||||||
cur int
|
cur int
|
||||||
@ -30,8 +30,8 @@ func NewPlaylist(filePath string, repeat bool) (*Playlist, error) {
|
|||||||
// Next returns the next song to play. Returns an empty string if repeat is
|
// Next returns the next song to play. Returns an empty string if repeat is
|
||||||
// false and the end of a playlist was reached.
|
// false and the end of a playlist was reached.
|
||||||
func (p *Playlist) Next() (song string) {
|
func (p *Playlist) Next() (song string) {
|
||||||
p.mut.Lock()
|
p.Lock()
|
||||||
defer p.mut.Unlock()
|
defer p.Unlock()
|
||||||
if p.cur == len(p.playlist) {
|
if p.cur == len(p.playlist) {
|
||||||
// If the end of a playlist was reached and repeat is set to true,
|
// If the end of a playlist was reached and repeat is set to true,
|
||||||
// then go back to the head of it, thus repeating it. Return an empty
|
// then go back to the head of it, thus repeating it. Return an empty
|
||||||
@ -53,10 +53,10 @@ func (p *Playlist) load() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.mut.Lock()
|
p.Lock()
|
||||||
p.playlist = strings.Split(string(data), "\n")
|
p.playlist = strings.Split(string(data), "\n")
|
||||||
p.cur = 0
|
p.cur = 0
|
||||||
p.mut.Unlock()
|
p.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user