ebaauw / homebridge-music

Homebridge plugin for iTunes with AirPlay speakers
Apache License 2.0
92 stars 7 forks source link

iTunes: could not set on to true #17

Closed DJay-X closed 4 years ago

DJay-X commented 4 years ago

Hi @ebaauw I hope you are doing well.

With update to v0.2.16 im getting an error and can't control Music App anymore. First start works and I can start the Apple Music App and also stoppt playing. Trying to start playing again brings then the error for whatever reason. Going back to v0.2.15 everything is working well again. Any Idea? Thanks in advance.

[2/22/2020, 4:20:52 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 4:20:53 PM] [iTunes] Apple TV 4K: on changed from false to true
[2/22/2020, 4:20:58 PM] [iTunes] iTunes: track changed from "" to "Broken Blues (feat. Andreya Triana)"
[2/22/2020, 4:21:13 PM] [iTunes] iTunes: set on from true to false
[2/22/2020, 4:21:17 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 4:21:17 PM] [iTunes] applescript setPlayerOn(true, "Broken Blues (feat. Andreya Triana)"): execution error: „Music“ hat einen Fehler erhalten: Einige Daten können nicht in den erwarteten Typ umgewandelt werden. (-1700)

[2/22/2020, 4:21:17 PM] [iTunes]             command: set lib to (load script "/usr/local/Cellar/node/12.12.0/lib/node_modules/homebridge-music/scripts/iTunes.scpt")
tell lib to setPlayerOn(true, "Broken Blues (feat. Andreya Triana)")
[2/22/2020, 4:21:17 PM] [iTunes] iTunes: could not set on to true
[2/22/2020, 4:21:33 PM] [iTunes] applescript getState(false): execution error: «class pAct» of item 9 of every «class cAPD» of application "Music" kann nicht in Typ Unicode text umgewandelt werden. (-1700)

[2/22/2020, 4:21:33 PM] [iTunes]             command: set lib to (load script "/usr/local/Cellar/node/12.12.0/lib/node_modules/homebridge-music/scripts/iTunes.scpt")
tell lib to getState(false)
[2/22/2020, 4:21:38 PM] [iTunes] Apple TV 4K: on changed from true to false
[2/22/2020, 4:21:42 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 4:21:42 PM] [iTunes] applescript setPlayerOn(true, "Broken Blues (feat. Andreya Triana)"): execution error: „Music“ hat einen Fehler erhalten: Einige Daten können nicht in den erwarteten Typ umgewandelt werden. (-1700)

[2/22/2020, 4:21:42 PM] [iTunes]             command: set lib to (load script "/usr/local/Cellar/node/12.12.0/lib/node_modules/homebridge-music/scripts/iTunes.scpt")
tell lib to setPlayerOn(true, "Broken Blues (feat. Andreya Triana)")
[2/22/2020, 4:21:42 PM] [iTunes] iTunes: could not set on to true
{
            "name": "iTunes",
            "service": "switch",
            "timeout": "25",
            "platform": "Music"
        },
ebaauw commented 4 years ago

Could you please, for comparison, also list the log for v0.2.15?

ebaauw commented 4 years ago

Are you running on Catalina or on an earlier version of macOS? homebridge-music uses the iTunes script, but the error message mentions the Music app?

ebaauw commented 4 years ago

iTunes (as well as Music) gives this error when specifying an unknown track to the play command. E.g. when sending (over AppleScript): tell application "Music" to play track "n/a", I get an error error "Music got an error: Can’t make some data into the expected type." number -1700 to item I cannot reproduce the other error, but it seems that Music is reporting an illegal track name that cannot be converted into a Unicode text. Not sure how this can happen, and why v0.2.16 would behave differently from v0.2.15. What were you playing when the error occurred?

DJay-X commented 4 years ago

Using macOS 10.15.3 Catalina, Music App 1.0.3.1.

Good you pointed to "illegal track name". Now I played the same track with v0.2.15 and it also was giving an error.

[2/22/2020, 5:33:57 PM] [iTunes] applescript error execution error: „Music“ hat einen Fehler erhalten: Einige Daten können nicht in den erwarteten Typ umgewandelt werden. (-1700)

[2/22/2020, 5:33:57 PM] [iTunes] applescript: set lib to (load script "/usr/local/Cellar/node/12.12.0/lib/node_modules/homebridge-music/scripts/iTunes.scpt")
tell lib to setPlayerOn(true, "Broken Blues (feat. Andreya Triana)")
[2/22/2020, 5:33:57 PM] [iTunes] iTunes: could not set on to true

Going to the next track manually and turning play on off and no error. But that particular track info doesn't show any strange to me.

Bildschirmfoto 2020-02-22 um 17 37 30

With v0.2.15

[2/22/2020, 5:29:12 PM] [iTunes] Initializing Music platform...
[2/22/2020, 5:29:12 PM] [iTunes] homebridge-music v0.2.15, node v12.16.1, homebridge v0.4.50
[2/22/2020, 5:29:12 PM] [iTunes] warning: not using recommended node version v12.14.1 LTS
[2/22/2020, 5:29:12 PM] [Config] Initializing config platform...
[2/22/2020, 5:29:12 PM] Loading 0 accessories...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'iTunes'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Computer'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Apple TV 4K'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Badezimmer'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Badezimmer(Audio)'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Schlafzimmer'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Schlafzimmer(Audio)'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Triby'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'Wohnzimmer'...
[2/22/2020, 5:29:12 PM] [iTunes] Initializing platform accessory 'ZIPP 2'...
[2/22/2020, 5:29:18 PM] [iTunes] Apple TV 4K: on changed from true to false
[2/22/2020, 5:29:23 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 5:29:28 PM] [iTunes] iTunes: track changed from "" to "lulu80XL"
[2/22/2020, 5:29:28 PM] [iTunes] Apple TV 4K: on changed from false to true
[2/22/2020, 5:29:42 PM] [iTunes] iTunes: set on from true to false
[2/22/2020, 5:29:50 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 5:33:28 PM] [iTunes] iTunes: volume changed from 19 to 24
[2/22/2020, 5:33:28 PM] [iTunes] iTunes: track changed from "lulu80XL" to "Broken Blues (feat. Andreya Triana)"
[2/22/2020, 5:33:28 PM] [iTunes] Computer: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Apple TV 4K: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Badezimmer: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Badezimmer(Audio): volume changed from 4 to 5
[2/22/2020, 5:33:28 PM] [iTunes] Schlafzimmer: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Schlafzimmer(Audio): volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Triby: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] Wohnzimmer: volume changed from 18 to 23
[2/22/2020, 5:33:28 PM] [iTunes] ZIPP 2: volume changed from 13 to 17
[2/22/2020, 5:33:53 PM] [iTunes] iTunes: set on from true to false
[2/22/2020, 5:33:57 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 5:33:57 PM] [iTunes] applescript error execution error: „Music“ hat einen Fehler erhalten: Einige Daten können nicht in den erwarteten Typ umgewandelt werden. (-1700)

[2/22/2020, 5:33:57 PM] [iTunes] applescript: set lib to (load script "/usr/local/Cellar/node/12.12.0/lib/node_modules/homebridge-music/scripts/iTunes.scpt")
tell lib to setPlayerOn(true, "Broken Blues (feat. Andreya Triana)")
[2/22/2020, 5:33:57 PM] [iTunes] iTunes: could not set on to true
[2/22/2020, 5:34:13 PM] [iTunes] Apple TV 4K: on changed from true to false
[2/22/2020, 5:34:18 PM] [iTunes] iTunes: on changed from false to true
[2/22/2020, 5:34:18 PM] [iTunes] iTunes: track changed from "Broken Blues (feat. Andreya Triana)" to "Ride It"
[2/22/2020, 5:34:18 PM] [iTunes] Apple TV 4K: on changed from false to true
[2/22/2020, 5:34:27 PM] [iTunes] iTunes: set on from true to false
[2/22/2020, 5:34:31 PM] [iTunes] iTunes: set on from false to true
[2/22/2020, 5:34:48 PM] [iTunes] iTunes: on changed from true to false
ebaauw commented 4 years ago

But that particular track info doesn't show any strange to me.

I'm afraid there's nothing I can do about this. You might try and delete and re-type the song title in case it contains any funny invisible characters, but that's really a long shot.

Using AppleScript to control iTunes still remains a bit of a hack. I created homebridge-music before I went all-in on Sonos, to automate through HomeKit turning AirPlay speakers on and off when entering or leaving the room. And to turn on the music when I arrive home or wake up, and turn it off when leaving or going to sleep. It's by no means a full-featured app to control iTunes (or now Music).

Using macOS 10.15.3 Catalina, Music App 1.0.3.1.

I'll add a check for the macOS version, and default to the Music script when it's Catalina or later. I did find some subtle differences between iTunes and Music in how they interact with AppleScript.

DJay-X commented 4 years ago

to automate through HomeKit turning AirPlay speakers on and off when entering or leaving the room. And to turn on the music when I arrive home or wake up, and turn it off when leaving or going to sleep.

Thats exactly the same use for me. Wouldn't want to miss your plugin and I appreciate your work and the time you are investing. 😌🙏

My config entry is still correct, even with Catalina and Music App, right? Theres not much and not more I have to add.

{
            "name": "iTunes",
            "service": "switch",
            "timeout": "25",
            "platform": "Music"
        },
ebaauw commented 4 years ago

There seems to be some magic at work that translates "iTunes" to "Music" when executing a compiled script, but not when compiling the script.

I noticed when setting the volume of an AirPlay speaker through Music, the volume is set to 1 less, causing homebridge-music to log an error. In the Music script I echo back the volume requested, and let the value be updated during the next heartbeat. You might want to add "Script": "Music" for now, to prevent the error. You might also just ignore it. The next version of homebridge-music will use Music script by default on Catalina (and beyond).

With the change to dynamic platform accessories, I plan to introduce some of the homebridge-zp features, notably Change Volume so you can set relative volume from HomeKit automations, e.g. from wireless switches. Especially fun in combination with homebridge-hue exposing switches with a dial, like the IKEA SYMFONISK controller or Lutron Aurora.