func listDirRec(path *vfs.Path) ([]*vfs.Track, error) { var tracks []*vfs.Track if path.IsDir() { entries, err := path.List() if err != nil { return nil, err } for _, e := range entries { if dir, ok := e.(*vfs.Dir); ok { t, err := listDirRec(dir.Path) if err != nil { return nil, err } tracks = append(tracks, t...) } else if track, ok := e.(*vfs.Track); ok { tracks = append(tracks, track) } else { panic(nil) } } } else { track, err := path.Track() if err != nil { return nil, err } tracks = append(tracks, track) } return tracks, nil }
func (p *Player) Play(path *vfs.Path) error { // Fill VFS playlist. var dir *vfs.Path var pos int = -1 if path.IsDir() { dir = path } else { d, err := path.Parent() if err != nil { return err } dir = d } entries, err := dir.List() if err != nil { return err } p.plistsMu.Lock() defer p.plistsMu.Unlock() p.vfsPlist.Clear() for i, entry := range entries { if !entry.IsDir() { t := entry.(*vfs.Track) // Find position to start. if path.IsDir() && pos == -1 { pos = 0 } else if pos == -1 && *path == *t.Path { pos = i } p.vfsPlist.Append(t) } } p.curPlist = p.vfsPlist p.pt.Play(p.curPlist.Tracks(), pos) return nil }