Share your Ubuntu media with AppleTV 2 : Ubuntu + iTunes (WINE) + ATV2


The Apple TV 2 (ATV2) seems like a good bit of kit for the price certainly better value than the iPad HDMI connection kit. I picked up an ATV2 primarily to wirelessly share my iPad stowed photos (from the Apple Camera Connection kit) on a large LCD TV. Furthermore, I was also intending to share photos and music from my home server running Ubuntu to the ATV2. Not wanting to jail break the ATV2 I was thus sad to see a lack of either native uPnP or DLNA support on the ATV2 out of the box rendering my home server useless with respect to the ATV2... the solution was to install iTunes to my home server and use Apple HomeSharing feature to get access to my server based media. Here's how to do it:

 
The first challenge is iTunes is only available at this time for Mac or Windows, to install iTunes 7.2 on Linux I required a compatibility layer, here steps in Wine:

I no longer recommend using Wine and iTunes, I'd strongly suggest still under Ubuntu using VirtualBox + WinXP + iTunes, it performs well and is far more stable and less time consuming than Wine. Read here for a step by step guide.

If you want to try Wine here's the process...

Install Wine (10-15mins incl. download)
Wine allows you to run many Windows programs on Linux. Its homepage can be found at WineHQ.org. To install Wine open a new terminal and enter the following command into the terminal:

sudo apt-get install wine

Accept the EULA when prompted (the quickest way is to press Right on the keyboard and then press Enter).

Before using Wine, it is necessary to create the fake C: drive where your Windows applications will be installed. To do this, enter the following command into the terminal:

winecfg
 
You also have the option of configuring Wine via the Configure Wine option in the Applications > Wine menu. 

This will create a hidden folder (.wine) in your home directory containing the fake C: drive as well as registry files similar to those used in Windows. Once this directory is created, the Wine Configuration Window will appear. This window will allow you to customize a variety of settings for Wine, including which Windows Version that is emulated, drive mappings, DLL overrides, as well as application specific settings. Click the Ok button to close the window.


Install iTunes under Wine  (15-20mins incl. download)
To install Windows applications using Wine, follow these instructions, this was based on  iTunes 10.3 but I've also had success with 10.4. To check if the iTunes version is functional with wine check here.

1. Download the iTunes Windows application from Apple. Download the .EXE (executable).
2. Place it in a convenient directory (e.g. the desktop, or home folder).
3. Open the terminal, and cd into the directory where the .EXE is located.
4. Type wine the-name-of-the-application.extension (e.g. wine iTunesSetup.exe).

For me this was:
cd /home/username/Downloads && wine iTunesSetup.exe

This will start the .EXE using Wine. The installer should then run as it would in Windows, install the application to, select put it under C:\Program Files. 

Once installed iTunes will open, follow the prompts to complete your iTunes setup. I received the warning and continue to receive the warning:

'iTunes was not properly installed. If you wish to import or burn CDs, you need to reinstall iTunes.'

I continue to overlook (OK) this warning since I won't be importing or burning CDs; iTunes will be used to pick up pre-ripped media and it still works regardless of the warning, just click OK to proceed.


Issues with iTunes 10.04
Since moving up to 10.4, I've had a few teething issues, which were overcome as follows:

I've had issues launching iTunes under wine specifically getting wine to use the right filepath; so I have had to use the following command:

wine ~/.wine/dosdevices/c:/Program\ Files/iTunes/iTunes.exe
 

Then I've had issues with iTunes dying on startup, this I've overcome with the next solution. This solution isn't ideal as it disables the sound driver and I'm sure there's a better workaround.
 However, disabling the sound driver for me is no issue as I' using this iTunes purely for HomeSharing and I have no speakers on the box for playback.


Applications > Wine > Configure Wine > Audio > Sound Driver > Uncheck all
Applications > Wine > Configure Wine > Wine configuration > Audio > DirectSound >  Select Emulation


Sharing iTunes to Apple TV
Once iTunes is installed to share media to Apple TV without jail breaking the Apple TV you need to use HomeSharing; since at this time the Apple TV 2 on iOS4.2.2 does not natively support uPnP or DLNA. Here's how to get HomeSharing working:
  • Enable HomeSharing on the Apple TV under your Apple ID, this is under Settings > Computer. You will need to enter your Apple ID if you haven't previously.
  • Enable HomeSharing on iTunes under Ubuntu, this is under Advanced on the top iTunes menu.
  • Authorise iTunes to use your Apple ID if prompted, note you can authorize up to 5 computes/devices with your Apple ID
  • Optional: Rename your Ubuntu iTunes library, by default your iTunes library will pickup the username under which your iTunes instance is ran on Ubuntu this wasn't ideal for me. Under Edit > Preferences (this takes several minutes to open for me under Wine) rename your iTunes library, then click Apply, and the cross to close the prompt.
Finally on your Apple TV goto Computers and your Ubuntu iTunes library shares should be apparent! If you have a firewall in place you may need to configure it, specifically you need to allow ports:
  • TCP 3689 
  • TCP 49152 
  • UDP 5353 
To run iTunes again in future under Ubuntu it should now be located under: 

Applications > Wine > Programs > iTunes > iTunes 

It may take a few minutes to open iTunes, personally I plan to leave it open permanently to facilitate HomeSharing since once iTunes is closed then HomeSharing of content for the PC it is on will not be available.

UPDATE July 2011: Upgrading iTunes isn't so easy, neither is uninstalling iTunes under wine, look out for a new post soon that covers this off.

UPDATE July 2011: I've now moved to iTunes 10.4 occassionally I have issues running iTunes via wine the best solution I have found to overcome problems is to follow the below, I intend at some point to wrap this into a simple shell script.

Check if iTunes and wine already have processes running and kill them:

ps -ae | grep itunes

note the PID

kill <INSERT PID>


ps -ae | grep wine 

note the PID  

kill <INSERT PID> 

Then manually launch iTunes from CLI
wine ~/.wine/dosdevices/c:/Program\ Files/iTunes/iTunes.exe

Adding iTunes to the list of Ubuntu startup programs (i.e. so you can boot your server and for iTunes to kick off on boot) wasn't a success for me so I will set up an rc.d script to launch it on boot manually probably after a time delay . Note this is only my experience against iTunes v10.4.

5 comments:

  1. Does AirPlay work with this setup. IE can I use my iPad as a remote?

    ReplyDelete
    Replies
    1. equally avoid Wine for a virtual machine if you can

      Delete
  2. Yes, you can use iTunes remote library sharing to share the server library to the iPad and then use Airplay on the iPad to stream to the Apple TV. Or you could use the remote app to control iTunes on the server and set iTunes to Airplay direct to the Apple TV, this is probably the better route.

    ReplyDelete
    Replies
    1. Wow. Thanks for the quick response.

      Delete