[GH-ISSUE #77] Unable to play a playlist in go-librespot using the Spotify API #60

Closed
opened 2026-02-28 14:25:01 +03:00 by kerem · 2 comments
Owner

Originally created by @felixstorm on GitHub (Sep 2, 2024).
Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/77

When trying to play a playlist using the Spotify API with go-librespot (0.0.17 as well as current master), I get the following error:

ERRO[0062] failed unmarshalling dealer request payload   error="json: cannot unmarshal number into Go struct field RequestPayload.target_alias_id of type string" uri="hm://connect-state/v1/player/command"

I added some debug statements and apparently the JSON that is being received looks like this (formatting for readability):

{
    "message_id": 860749268,
    "target_alias_id": 0,
    "sent_by_device_id": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36",
    "command": {
        "endpoint": "play",
        "context": {
            "uri": "spotify:playlist:37i9dQZF1DX7F6T2n2fegs",
            "url": "context://spotify:playlist:37i9dQZF1DX7F6T2n2fegs"
        },
        "play_origin": {
            "device_identifier": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36"
        },
        "options": {},
        "logging_params": {
            "device_identifier": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36"
        }
    }
}

Changing the type of TargetAliasId from string to uint32 seems to fix this problem, but then the code will panic later on:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x916012]

goroutine 1 [running]:
main.(*AppPlayer).handlePlayerCommand(_, {0x334fdf7f, 0x0, {0xc00013d140, 0x27}, {{0xc000015dd0, 0x4}, {0x0, 0x0}, {0x0, ...}, ...}})
        .../go-librespot/cmd/daemon/player.go:223 +0x1f2
main.(*AppPlayer).handleDealerRequest(_, {0xc00029c360, {0xc00013c690, 0x24}, {0x334fdf7f, 0x0, {0xc00013d140, 0x27}, {{0xc000015dd0, 0x4}, ...}}})
        .../go-librespot/cmd/daemon/player.go:336 +0xe8
main.(*AppPlayer).Run(0xc000056800, 0xc0000444e0)
        .../go-librespot/cmd/daemon/player.go:520 +0x565
...

Thereafter I commented out the statements causing the segfault and then it seems to finally work. But unfortunately I do not have any real experience with any of the Spotify Connect APIs to estimate whether my first change is appropriate and why the segfault happens or what to do to fix it...

Also see:

Originally created by @felixstorm on GitHub (Sep 2, 2024). Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/77 When trying to play a playlist using the Spotify API with go-librespot (`0.0.17` as well as current `master`), I get the following error: ``` ERRO[0062] failed unmarshalling dealer request payload error="json: cannot unmarshal number into Go struct field RequestPayload.target_alias_id of type string" uri="hm://connect-state/v1/player/command" ``` I added some debug statements and apparently the JSON that is being received looks like this (formatting for readability): ```json { "message_id": 860749268, "target_alias_id": 0, "sent_by_device_id": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36", "command": { "endpoint": "play", "context": { "uri": "spotify:playlist:37i9dQZF1DX7F6T2n2fegs", "url": "context://spotify:playlist:37i9dQZF1DX7F6T2n2fegs" }, "play_origin": { "device_identifier": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36" }, "options": {}, "logging_params": { "device_identifier": "webapi-cfc0c47944b9400cb5db4f8faf9cbe36" } } } ``` Changing the type of `TargetAliasId` from `string` to `uint32` seems to fix this problem, but then the code will panic later on: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x916012] goroutine 1 [running]: main.(*AppPlayer).handlePlayerCommand(_, {0x334fdf7f, 0x0, {0xc00013d140, 0x27}, {{0xc000015dd0, 0x4}, {0x0, 0x0}, {0x0, ...}, ...}}) .../go-librespot/cmd/daemon/player.go:223 +0x1f2 main.(*AppPlayer).handleDealerRequest(_, {0xc00029c360, {0xc00013c690, 0x24}, {0x334fdf7f, 0x0, {0xc00013d140, 0x27}, {{0xc000015dd0, 0x4}, ...}}}) .../go-librespot/cmd/daemon/player.go:336 +0xe8 main.(*AppPlayer).Run(0xc000056800, 0xc0000444e0) .../go-librespot/cmd/daemon/player.go:520 +0x565 ... ``` Thereafter I commented [out the statements causing the segfault](https://github.com/devgianlu/go-librespot/blob/08a2271786f6947c5b02393b393c2b70d18428e2/cmd/daemon/player.go#L223-L225) and then it seems to finally work. But unfortunately I do not have any real experience with any of the Spotify Connect APIs to estimate whether my first change is appropriate and why the segfault happens or what to do to fix it... Also see: - https://github.com/volumio/volumio-plugins/issues/664 - https://community.volumio.com/t/new-2023-spotify-plugin/63381/113
kerem 2026-02-28 14:25:01 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@devgianlu commented on GitHub (Sep 2, 2024):

Since Spotify does not know what type target_alias_id should have and we are not using it I've removed it. Also fixed the subsequent problem you had regarding the player options overrides.

<!-- gh-comment-id:2325133426 --> @devgianlu commented on GitHub (Sep 2, 2024): Since Spotify does not know what type `target_alias_id` should have and we are not using it I've removed it. Also fixed the subsequent problem you had regarding the player options overrides.
Author
Owner

@felixstorm commented on GitHub (Sep 3, 2024):

Great, thanks a lot!

<!-- gh-comment-id:2325627609 --> @felixstorm commented on GitHub (Sep 3, 2024): Great, thanks a lot!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-librespot#60
No description provided.