Question

I just fired up the new Netflix app for iOS and upon trying to AirPlay the video to my Apple TV, I got this message:

You

So I was wondering how they're able to do this. Is there a public API that lets an app retrieve the version of the Apple TV that's selected for AirPlay? Or does Netflix use some other means to detect this?

Was it helpful?

Solution

It's actually not that difficult to be able to pull something like this off. We're going to need to be doing two things: 1) listening for when the audio route changes to know when we've connected to an AirPlay device, and 2) searching the network for AirPlay devices to get info from.

Once we get notified when the audio route changes, we can get info about the new route. The most important bit for us is the name of the output port for the AirPlay device. Once we have that, we can iterate through all the AirPlay devices we know about to find the one that matches the name of the output port. Once we have that device, we can get info from its TXT record, which contains info about the version of the software its running.

I've pushed a sample project to Github that details how I pulled this off. This is a really simple project that just handles when a route changes. If you wanted to go live with this code, then you'd also want to add checks at certain other places, like when you present an MPMoviePlayerViewController.

EDIT: Note that this is pretty hacky, as we rely on the name of the port to be the same as the name of the AirPlay device. If Apple changes either of those things, this breaks. Alternatively, you can compare the "deviceid" field of the TXT record of the device to the UID of the port, which is the deviceid with the string "-airplay" appended to it, as far as I can tell. Again, if that is changed by Apple, it would break, but at least it's another potential way of checking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top