1
0

In Playlist embed a sync.Mutex instead.

This commit is contained in:
Alexander Andreev 2023-10-04 18:37:13 +04:00
parent 6ce4700420
commit 10bc3a3785
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -11,7 +11,7 @@ import (
// Playlist holds a list of paths to a song files.
type Playlist struct {
mut sync.Mutex
sync.Mutex
filePath string
playlist []string
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
// false and the end of a playlist was reached.
func (p *Playlist) Next() (song string) {
p.mut.Lock()
defer p.mut.Unlock()
p.Lock()
defer p.Unlock()
if p.cur == len(p.playlist) {
// 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
@ -53,10 +53,10 @@ func (p *Playlist) load() error {
if err != nil {
return err
}
p.mut.Lock()
p.Lock()
p.playlist = strings.Split(string(data), "\n")
p.cur = 0
p.mut.Unlock()
p.Unlock()
return nil
}