IntroductionIn this snippet, i will show how to check Media element is locked or not windows phone using C#.If you've used the Media element on Windows Phone (or one of the other media related components) then you probably know that it won't work with the phone is connected to Zune. But Zune is needed for debugging. So how do you debug if part of your software package renders your phone half-functional while you are debugging?! Well, you don't actually need to have Zune running to debug. There was a command line utility in the October update to the Windows Phone Developer Tools called WPConnect.exe. Upon connecting your phone to your computer Zune will open. Close it and run WPConnect.exe and you'll be able to deploy , run, and debug without your media library being crippled.
But after distribution of your program it's still possible for a user to have their media functionality locked if they try to run the program you wrote while the phone is connected to Zune. You'll probably want to notify the user of what must be done to unlock the full functionality of your program. Eric Fleck of Microsoft had a suggestion that seems to work pretty well (original source here). In short he checks to see if the phone reports that it is connected to an Ethernet adapter. If it does then chances are it is connected to a computer with Zune. There are scenarios in which the phone could report that it is connected to an Ethernet adapter while the media file is not locked (ex: when connected using WPConnect.exe). The code is pretty simple: Implementation void CheckNetworkStatus()
{
if (NetworkInterface.GetIsNetworkAvailable())
{
if (NetworkInterface.NetworkInterfaceType ==
NetworkInterfaceType.Ethernet)
{
MediaState = "Possibly locked, disconnect Zune";
return;
}
}
MediaState = "All's Well! Media is available!";
}That's all. Download Sample ProjectDownload source files -84 kb |