How to check Media Element is Locked in Windows Phone

No.of Views1505
Bookmarked0 times
Downloads 
Votes0
By  j2inet   On  10 Dec 2010 07:12:22
Tag : Windows Phone , How to
In this snippet, i will show how to check Media element is locked or not windows phone using C#.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In 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 Project

Download source files -84 kb

 
Sign Up to vote for this article
 
About Author
 
j2inet
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    You've got a class that contains data that you want to be able to save and load in IsolatedStorage on Windows Phone 7. How would you go about doing that? There is more than one way, but I wanted to share a generic solution for didactic purposes; I'm finding that many beginners like to start off with a single satisfying solution and brance off into specialized solutions later. Let's say that you are starting off with a stereotypical Employee class.
    Published Date : 05/Mar/2011
    In this article, i'm going to show to you,How to get System Information on Windows Phone 7
    Published Date : 06/Nov/2010
    In this article, i'm going to show to you, How to use DynameicSoundEffectInstance in Windows Phone 7
    Published Date : 06/Nov/2010
    I'm writing a rather lengthy piece on Windows Phone programming and rather than wait for the entire piece to be completed I've decided to start making the sections available in draft form. My intent is to cover XNA (2D and 3D) and Silverlight concepts.
    Published Date : 20/Nov/2010
    This article will get a .Net developer started with Windows Phone 7 development and introduce the basic application models and services available in Windows Phone 7 and more.
    Published Date : 10/Nov/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top