Building a Vista Media Center plugin

All I want to do is watch hulu.com movies on my TV instead of my laptop. This is much easier said than done though. The development tools seem to have stalled a few years ago. Is anyone else writing these things these days?

This post gives bad news: Flash is not coming to MCE anytime soon. So in order to get the Flash videos playing you have to render the ordinary Flash object inside a page, and have the plugin navigate to that page.

First off, I’m not the only one doing this. TunerFreeMCE, a closed-source plugin written by the author of the blog above, does the same thing for BBC shows and Hulu. Unfortunately it seems broken at the moment for Hulu content, but that’s probably easily fixed. Perhaps they changed their HTML format or something.

Main things I learned in the writing of my first plugin:

The Media Center SDK version 5.3 (which I think is the latest) has some issues.

  1. It contains a solution (MCMLSampler) that doesn’t build in VS 2008. It can’t find any of the MediaCenter DLL references, and try as I might I couldn’t add them manually either. So you can use the solution to browse the code but you can’t build it.
  2. There are hardcoded WiX binary paths in the MSI build batch file Build.bat. Sloppy, Redmond!
  3. Don’t forget to edit DevInstall.cmd if you add any non-DLL’s to your plugin; otherwise they won’t get copied to Program Files.
  4. DevInstall.cmd /u /debug works but DevInstall.cmd /debug /u does not.

The design and debugging process leaves a lot to be desired.

  1. I haven’t found any way to F5-debug the application directly. I can install the plugin into MCE via DevInstall.cmd (which installs it into the GAC) and then attach to the process but that’s it. If you set the registry key in C:\Program Files\Microsoft SDKs\Windows Media Center\v5.0\Tools you end up spawning a dialog window upon launch to give time to attach to the process. This post recommends a macro to make it quicker but I haven’t tried it.
  2. You can debug your markup via F5-debug but it will crash if you have any code-behind dependencies. This makes it fairly useless IMHO.
  3. There’s no visual designer (at least that I’ve found). So you have to lay out the markup manually, like in the early WPF days. And when you don’t have any good-looking templates to start from, the results look like crap.
  4. I did find the MCMLookalike project to develop open-source templates plugin developers could use to better match the MCE UI. It ceased last year due to a lack of community support but it was really helpful to see how a good MCE developer would write the MCML. You have to dig for the source code, but it’s there. I had to rebuild the VS 2008 project to get it running; that’s available here: mcmlookalike-vs2008.zip
  5. You can set several command-line options in MCMLPad during debugging. I added screen resolution, for example, so in the “Command-line arguments” under the Debug tab, I have the following to test 1280×720 (what the default “windowed”) launch of MCE is on Vista):
  6. -load:"resx://HuluMCE/HuluMCE.Resources/Test" -assemblyredirect:"C:\shared\projects\hulu\HuluMCE\bin\Debug" -markupredirect:"resx://HuluMCE/HuluMCE.Resources/,file://C:\shared\projects\hulu\HuluMCE\Markup\,.mcml" -size:1280,720
    

When I get a bit further along I’ll post the code, and built project, so you can see it in action.

NukeboxPerl, a web-based music jukebox

I originally wrote this in 2004. This was built with some pretty old-school stuff (e.g., running PostgreSQL and Apache on cygwin). Yikes. I’ve since rewritten it for WAMP. There is some interesting stuff in that zipfile though, such as a hack to remove DRM from WMA files and a metadata database that include AMG tags and song lyrics… Not bad for the time.

iTunes and WMP choking on your library? This is a web-based music jukebox designed for really large catalogs.

There are a ton of jukeboxes out there (from iTunes, to Windows Media Player, to Songbird, to about a zillion others), and they all look beautiful, have album metadata, etc. Unfortunately, the problem with all of them is they come to a chokling halt once you have more than, say, a few thousand songs. XMLdata storage is just not efficient enough to support the large record sets that arise if you have tens of thousands of songs to manage.

My solution to this is NukeboxPerl – a frontend to a RDBMS (in this case, PostgreSQL, but MySQL etc. would work just as well). I started this in 2002. It actually began life as a desktop .NET app but I switched to a server-based LAMP platform.

This Apache/modPerl/PostgreSQL web application was built to:

  • Handle collections of tens of thousands of files without noticeable performance degradation.
  • Transparently handle MP3, WMA and optionally unprotected MPEG-4 files. DRM-protected WMA files can even have the DRM removed for your convenience
  • Run on old, slow hardware. I run it on a 500 MHZ Pentium II, circa 1999.
  • Be entirely, 100% free to use.
  • I haven’t had time to work on this for awhile. If I was to pick it up again, the first thing I would do would be port it to PHP5 and make it completely object-based.

Operating System Requirements: Windows 2000/XP with Cygwin Linux-emulation package installed.

Download it: NukeboxPerl

Developing with the Windows peer-to-peer framework

A few months ago I investigated various options to build P2P apps that could be run across the internet, regardless of hardware and ISPs.

The research started with Java, which is JXTA (aka Juxtapose) – the framework started by Sun in 2001. I suspect the open-source P2P filesharing clients all use it (since they all seem to be Java). It has been ported to C/C++ (which I was eventually able to compile on Win32). I was unable to get the .NET wrapper running (which is known to be incomplete anyway).

Thus I was stuck. Research continued and I eventually got to the WCF P2P framework. I’m not sure of the additions in 3.5 vs. 3.0. For starters check out:

  1. this project on CodeProject which is the basis of WPFChat
  2. This MSDN blog which describes the PictureViewer project (interesting forum post here)
  3. Windows Meeting Space uses it (at least for Vista), so it is a scenario that Redmond is aware of.

That said, is this supposed to be possible for 3rd-party developers? See my forum post where I asked around – net consensus was “sort of”, which I eventually confirmed. Read on.

Running the PNRP service

PNRP is the name resolution protocol. Service is running by default on Vista, but if it’s not do this. On XP, you need the Advanced Networking Pack (if you’re pre-SP2). If you are SP2+, you get it but need to enable it. But according to this post, though, maybe SP2 doesn’t get it for free after all? Who knows.

From MSDN:

To install PNRP on Windows XP SP2 (one-time setup):

  1. In the Control Panel, double-click Add or Remove Programs.
  2. In the Add or Remove Programs dialog box, click Add/Remove Windows Components.
  3. In the Windows Components Wizard, select the “Networking Services” check box and click “Details”.
  4. Check the “Peer-to-Peer” check box and click “OK”.
  5. Click “Next” in the Windows Components Wizard.
  6. When the installation completes, click “Finish”.
  7. From a command shell prompt, start the PNRP service with the following command: net start pnrpsvc.

Then you can check install by running

> netsh p2p pnrp cloud show list

You should see at least a link local and a global PNRP cloud. If you’re missing the Global_ cloud, you’ll need to take some extra steps to get IPv6 working. In that case see this debugging guide.

Troubleshooting the PNRP service

If you run:

> netsh p2p pnrp cl sh st *

and get:

Scope  Id     Addr   State             Name
-----  -----  -----  ----------------  -----
    1      0      1  Virtual           Global_

Synchronize server:     pnrpv2.ipv6.microsoft.com;pnrpv21.ipv6.microsoft.com
Use Server:             Not used
Use SSDP:               Not used
Use Persisted cache:    Not used

Scope  Id     Addr   State             Name
-----  -----  -----  ----------------  -----
    3      4      1  Virtual           LinkLocal_{C3D2D7B6-FEF3-4CA2-9238-4EC716
142528}

Synchronize server:
Use Server:             Disabled
Use SSDP:               Not used
Use Persisted cache:    Not used

then run

> netsh p2p pnrp cloud start Global_

Opening ports in the firewall

Manually opening ports (may not be needed).The above steps seem to set up PNRP outside the Windows Firewall (since they don’t show as exceptions). 3rd party products like Norton could be another story. The ports necessary to be open are TCP (2869) and UDP (1900).

Allowing edge traversal in the firewall rule

(Vista only) The first time you run a PNRP-enabled executable you should get a Windows Firewall warning. That’s all you need for XP, but this however is not sufficent if you’re on Vista! As per the answer on this post, then open up the Windows Firewall Advanced control panel, select the UDP rule that just got created, right-click to get the properties, and then under the Advanced tab, check “Allow edge traversal”. Then OK out and repeat for the TCP rule.

Fortunately this can be done via netsh and programmatically as well.

Enabling Ipv6 Ping

See this MSDN post – looks like the magic command (on Vista anyway) is

netsh advfirewall firewall add rule name="ICMPv6 Inbound" dir=in action=allow enable=yes \
   profile=any localip=any remoteip=any protocol=icmpv6:128,any interfacetype=any edge=yes

Troubleshooting WCF and netsh

This blog posting has a technique for piping WCF debug output to a file. Immensely helpful. The file can be viewed by the ServiceTraceViewer, a tool located in “C:\Program Files\Microsoft SDKs\Windows\v6.1\bin\”

Also here is the TechNet page for the netsh command syntax.