1package main
2
3import (
4 "github.com/nmeum/mpvfs/fileserver"
5 "github.com/nmeum/mpvfs/mpv"
6 "github.com/nmeum/mpvfs/playlistfs"
7
8 "strings"
9)
10
11type playvol struct {
12 *playlistfs.BlockRecv
13
14 state *playerState
15 mpv *mpv.Client
16}
17
18func newVol() (fileserver.File, error) {
19 p := &playvol{state: state, mpv: mpvClient}
20 p.BlockRecv = playlistfs.NewBlockRecv(p)
21 return p, nil
22}
23
24func (c *playvol) CurrentReader() *strings.Reader {
25 v := playlistfs.Volume{Levels: []uint{c.state.Volume()}}
26 return strings.NewReader(v.String() + "\n")
27}
28
29func (c *playvol) NextReader() *strings.Reader {
30 v := playlistfs.Volume{Levels: []uint{c.state.WaitVolume()}}
31 return strings.NewReader(v.String() + "\n")
32}
33
34func (c *playvol) Write(off int64, p []byte) (int, error) {
35 vol, err := playlistfs.VolCmd(p)
36 if err != nil {
37 return 0, err
38 }
39
40 // TODO: handle channels
41 level := float64(vol.Levels[0])
42 err = c.mpv.SetProperty("volume", level)
43 if err != nil {
44 return 0, err
45 }
46
47 return len(p), nil
48}
49
50func (c *playvol) Close() error {
51 return nil
52}