Update music control implementation

This commit is contained in:
Elara 2021-11-24 16:44:36 -08:00
parent 5d231207cd
commit 8aada58d64
3 changed files with 15 additions and 38 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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()