petro-kushchak / homebridge-homepod-radio

MIT License
39 stars 2 forks source link

Error: This callback function has already been called by someone else; it can only be called one time #38

Open giuliomagnifico opened 1 year ago

giuliomagnifico commented 1 year ago

Hello, thank for this plugin that seems great, I integrated it in my HomeBridge installation (with some issue to compile atvremote) but now when I try to play something via a shortcut I get this error:

As a straming url I'm using http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one for test.

[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Triggered SET TargetMediaState: 0
[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Triggered SET Speaker ON: 0
[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Started hearbeat 619
[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one
Error: This callback function has already been called by someone else; it can only be called one time.
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:12:13
    at /var/lib/homebridge/node_modules/@petro-kushchak/homebridge-homepod-radio/src/lib/homebridgeCallbacks.ts:19:34
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] Child bridge process ended
[05/09/2023, 08:44:04] [@petro-kushchak/homebridge-homepod-radio] Process Ended. Code: 1, Signal: null
[05/09/2023, 08:44:11] [@petro-kushchak/homebridge-homepod-radio] Restarting Process...

Thanks

petro-kushchak commented 1 year ago

Hi, interesting... Could you share more details on which version of the plugin + pyatv are you using?

giuliomagnifico commented 1 year ago

Thanks for the reply, I was using the v2.0.0 now I just updated to v3.0.0 (congrats on the release). But I got the same issue and error.

homebridge-homepod-radio v3.0.0
atvremote 0.14.0

IMG_C56F7001482A-1

[07/09/2023, 12:15:39] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Triggered SET TargetMediaState: 0
[07/09/2023, 12:15:39] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Triggered SET Speaker ON: 0
[07/09/2023, 12:15:39] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Started hearbeat 1341
[07/09/2023, 12:15:39] [@petro-kushchak/homebridge-homepod-radio] [Rai News 24] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one
Error: This callback function has already been called by someone else; it can only be called one time.
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:12:13
    at /var/lib/homebridge/node_modules/@petro-kushchak/homebridge-homepod-radio/src/lib/homebridgeCallbacks.ts:19:34
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
[07/09/2023, 12:15:39] [@petro-kushchak/homebridge-homepod-radio] Child bridge process ended
petro-kushchak commented 1 year ago

Looks like you are trying to use shortcut to play radio using Speaker accessory?

With iOS 16/17 there are issues with custom speaker accessory (I hoped there will be improvements in iOS 17, but looks like it's time to depreciate it in the plugin). For each radio you can add Switch accessory, which is properly supported by iOS 16/17 and works fine with shortcuts.

giuliomagnifico commented 1 year ago

Okay, got it, but now I'm facing another error:

[08/09/2023, 08:01:19] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno Switch] SET ON: true
[08/09/2023, 08:01:19] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno] Started hearbeat 1029
[08/09/2023, 08:01:19] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one
[08/09/2023, 08:01:34] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno] streaming exit: code 0 signal null
[08/09/2023, 08:01:34] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno] Cleared hearbeat 1029 - stop requested
[08/09/2023, 08:01:34] [@petro-kushchak/homebridge-homepod-radio] [Rai News bagno] Error while trying to stop: Error: Command failed: kill -9 18426
/bin/sh: 1: kill: No such process

And I have another issue, I have one HomePod Mini in bathroom and home HomePod in the lounge room, I added both to the config but I see only the HomePod Mini and not the other HomePod, I mean that if I search to add the other "switch/speaker/volume" I don't find the second one ("Rai News salotto"), ony the one I already added ("Rai News bagno"), here's my config:

        {
            "homepodId": "94:EA:32:95:B0:58",
            "httpPort": 7654,
            "enableVolumeControl": true,
            "verboseMode": false,
            "radios": [
                {
                    "name": "Rai News bagno",
                    "radioUrl": "http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one",
                    "onSwitch": true,
                    "artworkUrl": "https://www.rainews.it/dl/rainews/images/social/live.png"
                }
            ],
            "_bridge": {
                "username": "0E:2C:21:51:C6:96",
                "port": 49312
            },
            "platform": "HomepodRadioPlatform"
        },
        {
            "homepodId": "ACBCB5F31293",
            "httpPort": 7654,
            "enableVolumeControl": true,
            "verboseMode": false,
            "radios": [
                {
                    "name": "Rai News salotto",
                    "radioUrl": "https://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=1&output=16",
                    "onSwitch": true
                }
            ],
            "platform": "HomepodRadioPlatform"
        }
    ],
giuliomagnifico commented 1 year ago

Edit, sorry for the double post, but I found the issue: is the streaming url!

https://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=1&output=16

Probably because it creates a unique ID everytime is launched, and via ffmpeg it doesn't work. I don't know why. If I open the above url in my browser the url redirects to

https://rainews1-live.akamaized.net/hls/live/598326/rainews1/rainews1/playlist.m3u8?hdnea=st=1694174121~exp=1694174271~acl=/*~hmac=807e6946eac9ef681a4f111bf0af04d140eac44648f88ef8584eb0446ca8a100

and if I use this url in your plugin, then it works perfectly also via Home app!

Any tip for this issue?

petro-kushchak commented 1 year ago

Interesting - technically I could add to plugin support of some kind of "evaluation of final url after redirects", but probably there are already existing solutions for this... Maybe you can get another url for that radio stream?

giuliomagnifico commented 1 year ago

No unfortunately I can’t use other links, this is the official link that works in IINA, VLC, Apple TV, etc… there isn’t a setting/variable to pass to ffmpeg to avoid the issue?

a “health check” of the url would be nice by the way! Also a way to change the ffmpeg launch command (I mean add some custom options if needed).

petro-kushchak commented 1 year ago

Ok, will prepare some beta build in a next few days :)

petro-kushchak commented 1 year ago

@giuliomagnifico try to install v3.0.2-alpha, I've added validateRadioUrl setting (default false) - if set to true plugin will use follow-redirects library to evaluate final url :)

Also from UI each radio has "Validate/Evaluate Radio Stream URL with redirects" checkbox

To install alpha/beta versions use this how-to: https://github.com/homebridge/homebridge/wiki/How-to-Install-Alternate-Plugin-Versions

giuliomagnifico commented 1 year ago

Hi @petro-kushchak thank you very much for this alpha.

It works! 🥳 and it's also quite reliable the audio, switch and shortcut.

But the light on the HomePod Mini is not very reliable, I mean, when it's playing some times the white backlight is active, and sometimes not. Not sure why, it's annoying because without the light is harder to see the + and - buttons on it.

If you need I can make other tests.

I'm only not understanding why it doesn't work for the normal HomePod (not mini), it shouldn't be the same? I mean, the protocols are the same, why it isn't working?

If I try to add a second homepodId with the big HomePod and the same radio switch, I'm unable to find the switch when I search for a new accessory in Home app.

petro-kushchak commented 1 year ago

Hi, great - will prepare release then!

Regarding multiple HomePod support - its not supported yet, maybe in few weeks if I get enough time