Airfoil interacting with Airplay and Apple Remote

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

I set up an alarm clock "app" at the weekend with an old iPhone as the "bedside clock" that I use to set the alarm time and provide the Snooze and Off buttons.
I use Airfoil and the itunes plugins to play music to my wireless speakers connected by an Airport Express.
It all works great except if I've been using Apple Remote and Airplaying the iTunes music to a different set of speakers. It seems that Airfoil is not able to take control of the speaker routing if Airplay is enabled and pointing at different speakers.
If I deselect the speakers on iTunes, Airfoil is able to select the correct speaker routing.

Is there any way to override iTunes' Airplay assignment to allow Airfoil to do its thing?

Second issue seems to be a hit or a miss if the iTunes plugin Play function actually plays or not. It seems pretty random if it's going to work or not.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

alang_94526 wrote:Is there any way to override iTunes' Airplay assignment to allow Airfoil to do its thing?
Apparently not - if something is connected via Airplay nothing else can connect until it disconnects (which can happen after a timeout period but that appears to be internal so I don't know the rules).
alang_94526 wrote:Second issue seems to be a hit or a miss if the iTunes plugin Play function actually plays or not. It seems pretty random if it's going to work or not.
The only known issue is that controlling when listening to radio stations seems to work slightly differently than when controlling local media. Again, because there's no published API, I don't really know what the differences are. I never listen to radio stations and never have any issue with Play/Pause working correctly.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Re: Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

I dug around some more and found this link
http://bendodsonapps.com/weblog/2011/01 ... plescript/
which I adapted and stripped down to this:

Code: Select all

tell application "System Events"
	tell application "iTunes"
		set visible of front browser window to true
	end tell
	delay 0.2
	
	tell window "iTunes" of application process "iTunes"
		click button 10
		keystroke "C"
		keystroke return
	end tell
end tell
The front browser setting is not technically needed but essentially click button 10 selects the Airplay icon.
Pressing button C selects the computer's internal speaker which is the same thing as turning off Airplay
Then press return to make the selection.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

Cool, thanks for sharing!
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Re: Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

1 word of caution with the script above (as I found to my peril).
It doesn't work if you enable either screensaver or require a password to log in.
It is fine with Energy Saver setting the display to go off, but for some reason both screen saver and logging in seems to fail spectacularly.
What happens is the Airplay window does open, but then it halts and never completes the C or return and eventually times out.
To add to that, anything that Indigo thinks it's trying to do at the same time will stop working. I have security cameras that come up with epic failure logs during the time the script is trying to disable airplay.

I haven't found a way around this other than to disable the screensaver and remove the login password, neither of which are a big deal to me, but may not work for other people.
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Re: Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

The new iTunes 11 behaves a bit differently to iTunes 10.
Posting updated AS code which selects button 9 instead of 10 and for some reason, I had to extend the delay between C and return.

Code: Select all

ell application "System Events"
	tell application "iTunes"
		activate
		set visible of front browser window to true
	end tell
	delay 0.2
end tell

tell application "System Events"
	tell application "iTunes"
		activate
		set visible of front browser window to true
	end tell
	delay 0.2
	
	tell window "iTunes" of application process "iTunes"
		click button 9
		delay 0.2
		keystroke "C"
		delay 1
		keystroke return
	end tell
end tell
Now I have to figure out how to fix iTunes 11's broken Shuffle command
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Re: Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

With the installation of iTunes 11.0.3, this method stopped working or at least button 9 is no longer the Airplay button which means I have to go figure out the new button number allocation.
However, iTunes 11.0.3 has finally implemented Airplay support for Applescript so this clunky workaround is no longer required.
I found full details on Applescript support for Airplay at this very handy website:
http://dougscripts.com/itunes/category/itunes-11/

I'll spend some time next week dinking around with it but it looks like it will do the job and I won't even need Airfoil.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

Just an FYI - I just upgraded my 10.6.8 production server to iTunes 11.0.3 and it's crashing at least once a day. It could be something to do with my server but I just wanted to get the word out there.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
alang_94526
Posts: 250
Joined: Mon Apr 13, 2009 10:29 pm

Re: Airfoil interacting with Airplay and Apple Remote

Post by alang_94526 »

I've had iTunes 11.0.3 running on my OSX 10.8.3 for about a week now and it hasn't crashed yet (and I'd know about it too since I use it as an alarm clock ;-) )
Try updating your OSX and see if it magically corrects itself
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

Um, yeah, not gonna happen... :P

I know a lot of our users run Indigo on older hardware that doesn't necessarily support new OS releases...
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
AndrewGWalsh
Posts: 67
Joined: Wed Feb 20, 2013 5:23 am

Re: Airfoil interacting with Airplay and Apple Remote

Post by AndrewGWalsh »

I've upgraded to 11.0.3 too and have considerable instability now after script access to iTunes each day. I haven't got to the bottom of what usage causes it but I suspect that it is the use of Radio via iTunes - Airfoil is stable though.

If I learn anything useful I'll post it.


Andrew
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

I thought that might be it as well, so I rebooted and stopped using radio stations. Crash.

Sigh.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
AndrewGWalsh
Posts: 67
Joined: Wed Feb 20, 2013 5:23 am

Re: Airfoil interacting with Airplay and Apple Remote

Post by AndrewGWalsh »

My new suspicion is that it is changing playlists - for the last couple of days I have just started and stopped the same playlist. Changing to radio or another playlist programmatically (its fine if I control iTunes manually from the console) means I end up having to restart things.

Andrew
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Airfoil interacting with Airplay and Apple Remote

Post by jay (support) »

Well, I only change the playlist from the iTunes UI (never programmatically), so that's not the issue I'm seeing. FYI...
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
Locked

Return to “Extending Indigo with Plugins and Python”