Airplay Protocol

Airplay Protocol

I've spent a lot of time figuring out how to connect to my AppleTV and send it pictures, videos, music, etc... then i've realize that there is no documented protocol for it. Apple just mantains the interface for Cocoa and hides the undelying protocol

The research to make the airplay gem was slow, mainly because was only a proof of concept to communicate with the AppleTV from ruby.

General Info

One of the first things to know is that the Airplay Protocol uses a subset of HTTP to communicate, uses an upgraded connections PTTH and persistent connections to the resources.

Second generation AppleTV with iOS 5 will also broadcast Airtunes and Mirroring through the LAN.

Finding the server

The AppleTV will broadcast himself in the LAN using Bonjour). You can find yours browsing for '_airplay._tcp.'.

This will give you and Ip and a port, normally being :7000.

Photos

The resource for photos is "photo" there are only a few things that you can do here.

You cannot send the path of the image, you need to send it's content so if you wanted so send an image you could only:

      $ cat image.jpg
    

Or

      content = File.read(image_path)
    

Request

      # PUT /photo
      # X-Apple-Transition: None
      # Connection: Keep-Alive
      #
      # ... raw img content ...
      #
    

Please note the "X-Apple-Transition" header, this header is not mandatory with it you can create transitions between the current image and another.

The ones i've found are:

  • None
  • SlideLeft
  • SlideRight
  • Dissolve

Two of them will give the chance so simulate the slide as when seeing in an iPhone.

Request flow

+-----------+
|  AppleTV  +----+
+-----------+    |
                 |
       +---------+-----+
       |  PUT /photo   |
       |               |
       |  img content  |
       +---------+-----+
                 |
+----------+     |
|  Client  +-----+
+----------+

Video

The resource for videos is divided according for some it features, so you'll have "play", "stop", "rate".

play

Note three things:

  • There is a content in the body of the request, those are the 'commands' that make magic
  • The connection must be kept alive for all the time of the video playback.
  • The Start-Position command as it's name suggest will set the start position to n seconds of start.

Request

      # POST /play
      # Connection: Keep-Alive
      #
      # Content-Location: http://something.com/video.mp4
      # Start-Position: 0
      #
    

stop

This will stop (and end) the current playback

Request

      # POST /stop
      # Connection: Keep-Alive
      #
    

rate

This was a tricky one, rate it's just to pausing and resuming playback of media.

To pause:

      # POST /rate?value=0
      # Connection: Keep-Alive
      #
    

To play:

      # POST /rate?value=1
      # Connection: Keep-Alive
      #
    

Request flow

+-----------+
|  AppleTV  +----+
+-----------+    |
                 |
       +---------+---------------------------------------------------+
       |  POST /play                                                 |
       |                                                             |
       |  Content-Location: http://somewhere.com/overtherainbow.mp4  |
       |  Start-Position: 5                                          |
       +---------+---------------------------------------------------+
                 |
+----------+     |
|  Client  +-----+
+----------+