Making it Easier to Debug Media in Windows Phone 7 Apps
November 23, 2010 3 Comments
My current app requires me to mess around with media files on the device. I have my device plugged in and Zune software running. Simple, right? Well, not necessarily so. It seems that when you’re running the Zune software, the media library becomes locked and inaccessible to your app. This may be quite annoying when it comes to debugging and stepping through code on your device. Further more, if you’re running it on the locked emulator, you won’t have any music media to test with and so you have to debug on the device. Fortunately, MS have released the WPConnect tool to make this possible, but it means having to close the Zune software. If you run the Zune software, you have to run the tool again to allow media debugging. I like listening to my music whilst developing, so having to switch between the Zune software and WPConnect tool can get a bit tedious. I decided to integrate WPconnect into the Visual Studio IDE for quick access. I’m going to explain a quick and simple way of doing it.
Firstly, if you haven’t done so already, download the October 2010 Update (this is a small update, not the RTM SDK). This includes the WPConnect tool (along with the Capability Detection Tool and improved gesture support for the Bing Maps control).
You can simply run this tool (by default located in %ProgramFiles(x86)%\Microsoft SDKs\Windows Phone\v7.0\Tools\WPConnect or %ProgramFiles%\Microsoft SDKs\Windows Phone\v7.0\Tools depending on where you installed it). A command prompt window then flashes. This is fine, but I like to see confirmation that the phone connected successfully, so we’re also going to make it so that the command prompt window stays open and the confirmation (or error) message can be read.
Thanks to Chris Eargle for pointing out that you can simply untick the ‘Close on Exit’ button on the External Tools screen. This will keep the command prompt window open, so there’s no need to create the BAT file described below (unless you want to extend it to use TaskKill and close the Zune software automatically).
I’m not sure if you can pass an argument into the file to keep the command prompt window open so, instead, we’re going to create a batch file. If you don’t want the window to stay open, you can skip the BAT file creation. Open Notepad and type the following: @echo off cmd /K “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\WPConnect\WPConnect.exe”
Change the file path to the correct installation directory of your WPconnect tool (including speech marks). Save the file and make sure you save it with a “.bat” extension.
Now, in Visual Studio, go to Tools…External Tools… Click ‘Add’ and give it a title. As you can see from the image, I just called it WPConnect. Set the command path to be that of the BAT file you created above (or WPConnect.exe if you didn’t create a bat file) and the ‘Initial Directory’ to be the directory your BAT/EXE file is in. (Ignore the WP7 Capability Detection item in the image below. I did something similar with that to output the capabilities my app requires ).
Click OK and it’s done. Now, when you want to run from Visual Studio, you can go to Tools…WPConnect. If you don’t want the command prompt window to stay open, you can just have the command path point to the original WPConnect.exe file instead of creating a BAT file. Switching from Zune and this is now easier as Zune is pinned in my taskbar so altogether quite nice :). Of course, if you want to automatically close Zune when WPConnect is launched, you could extend the batch file with TaskKill.
Hope this is useful to those who like listening to music via the Zune software, yet need to debug media on the device. For more information on WPConnect, I highly recommend you read Jaime Rodriguez’s post “Tips for debugging WP7 media apps with WPConnect“.