Skip to content

Commit

Permalink
feat: move autoplay toggle to configuration
Browse files Browse the repository at this point in the history
Previously, the autoplay information was taken from the product info, but it appears it should be a device specific configuration.

Closes #133
  • Loading branch information
devgianlu committed Nov 5, 2024
1 parent 307f062 commit 62611cb
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ bitrate: 160 # Playback bitrate (96, 160, 320)
volume_steps: 100 # Volume steps count
initial_volume: 100 # Initial volume in steps (not applied to the mixer device)
external_volume: false # Whether volume is controlled externally
disable_autoplay: false # Whether autoplay of more songs should be disabled
```

Make sure to check [here](/config_schema.json) for the full list of options.
Expand Down
2 changes: 1 addition & 1 deletion cmd/daemon/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (p *AppPlayer) advanceNext(forceNext, drop bool) (bool, error) {
p.state.player.Timestamp = time.Now().UnixMilli()
p.state.player.PositionAsOfTimestamp = 0

if !hasNextTrack && p.prodInfo.AutoplayEnabled() {
if !hasNextTrack && !p.app.cfg.DisableAutoplay {
p.state.player.Suppressions = &connectpb.Suppressions{}

var prevTrackUris []string
Expand Down
1 change: 1 addition & 0 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ type Config struct {
NormalisationPregain float32 `koanf:"normalisation_pregain"`
ExternalVolume bool `koanf:"external_volume"`
ZeroconfEnabled bool `koanf:"zeroconf_enabled"`
DisableAutoplay bool `koanf:"disable_autoplay"`
Server struct {
Enabled bool `koanf:"enabled"`
Address string `koanf:"address"`
Expand Down
1 change: 0 additions & 1 deletion cmd/daemon/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (p *AppPlayer) handleAccesspointPacket(pktType ap.PacketType, payload []byt
}

p.prodInfo = &prod
log.Debugf("autoplay enabled: %t", p.prodInfo.AutoplayEnabled())
return nil
case ap.PacketTypeCountryCode:
*p.countryCode = string(payload)
Expand Down
5 changes: 0 additions & 5 deletions cmd/daemon/product_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ type ProductInfo struct {
Type string `xml:"type"`
HeadFilesUrl string `xml:"head-files-url"`
ImageUrl string `xml:"image-url"`
Autoplay string `xml:"autoplay"`
} `xml:"product"`
}

func (pi ProductInfo) ImageUrl(fileId string) string {
return strings.Replace(pi.Products[0].ImageUrl, "{file_id}", strings.ToLower(fileId), 1)
}

func (pi ProductInfo) AutoplayEnabled() bool {
return pi.Products[0].Autoplay == "1"
}
5 changes: 5 additions & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
"type": "boolean",
"description": "Whether volume is controlled externally, if true the app will not pre-multiply samples",
"default": false
},
"disable_autoplay": {
"type": "boolean",
"description": "Whether autoplay of more songs should be disabled",
"default": false
}
},
"required": [
Expand Down

2 comments on commit 62611cb

@aykevl
Copy link
Contributor

@aykevl aykevl commented on 62611cb Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) now I can disable autoplay again (I always have it disabled, was quite surprised when go-librespot suddenly started playing random songs).

I wonder how this is implemented for Spotify devices without a real UI? I guess there has to be some sort of toggle for it somewhere?

@devgianlu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am very confused about it too. Mainly because you get notified when the toggle changes in the UI from the desktop client, but there's no way to get the new value. Still no idea how it works for, let's say, a Sonos speaker.

Can't see it in the eSDK API reference either.

Please sign in to comment.