From 8aada58d6400a8f81555249c8f043f14f2d9e719 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 24 Nov 2021 16:44:36 -0800 Subject: [PATCH] Update music control implementation --- go.mod | 2 +- go.sum | 4 ++-- music.go | 47 ++++++++++++----------------------------------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/go.mod b/go.mod index dced2da..36e87e0 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/srwiley/oksvg v0.0.0-20210519022825-9fc0c575d5fe // indirect github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect github.com/yuin/goldmark v1.4.1 // indirect - go.arsenm.dev/infinitime v0.0.0-20211123052001-ec1548ec0f30 + go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6 golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect diff --git a/go.sum b/go.sum index ac53c58..8d98434 100644 --- a/go.sum +++ b/go.sum @@ -367,8 +367,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.arsenm.dev/infinitime v0.0.0-20211123052001-ec1548ec0f30 h1:nhuJfwWxBxfolMU5go3rBLhvl59HMRIMqEKi405Ja9w= -go.arsenm.dev/infinitime v0.0.0-20211123052001-ec1548ec0f30/go.mod h1:kNBKxQfqeLUfi13GM6tB1kSvLm8HlZ7PM47AYeJQIiw= +go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6 h1:pAwb4Z2LY+RD3I1VxklG8Vv8CV6szfikc9L/qM8nQmc= +go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6/go.mod h1:TzAhsz7TAqEm/vWhgMvmIxHS5jt46hqKkPvr6cqvVyA= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= diff --git a/music.go b/music.go index 7dac7d9..9f14712 100644 --- a/music.go +++ b/music.go @@ -26,45 +26,22 @@ import ( ) func initMusicCtrl(dev *infinitime.Device) error { - // On player status change, set status - err := player.Status(func(newStatus bool) { - if !firmwareUpdating { - dev.Music.SetStatus(newStatus) - } - }) - if err != nil { - return err - } + player.Init() - // On player title change, set track - err = player.Metadata("title", func(newTitle string) { + player.OnChange(func(ct player.ChangeType, val string) { if !firmwareUpdating { - dev.Music.SetTrack(newTitle) + switch ct { + case player.ChangeTypeStatus: + dev.Music.SetStatus(val == "Playing") + case player.ChangeTypeTitle: + dev.Music.SetTrack(val) + case player.ChangeTypeAlbum: + dev.Music.SetAlbum(val) + case player.ChangeTypeArtist: + dev.Music.SetArtist(val) + } } }) - if err != nil { - return err - } - - // On player album change, set album - err = player.Metadata("album", func(newAlbum string) { - if !firmwareUpdating { - dev.Music.SetAlbum(newAlbum) - } - }) - if err != nil { - return err - } - - // On player artist change, set artist - err = player.Metadata("artist", func(newArtist string) { - if !firmwareUpdating { - dev.Music.SetArtist(newArtist) - } - }) - if err != nil { - return err - } // Watch for music events musicEvtCh, err := dev.Music.WatchEvents()