Windows Phone 7 development

Posts tagged ‘Extensible Application Markup Language’

How to play music across pages.

Silverlight for Windows Phone 7 is based on the page  navigation system. Key point is the lifetime of pages – each page is deleted while you navigate to another. To have an object(singleton f.e.) during the whole application life it could be placed in App class (App.xaml.cs file). MediaElement is definitely an object that should be one (there must be only one music player). The best and simple solution is place the MediaElement in XAML(it needs to be a part of visual tree), I have used application resources:


<!--Application Resources-->
<Application.Resources>
   <MediaElement x:Name="mediaPlayer" Source="/Sound/horrorSong.mp3" AutoPlay="False"  />
</Application.Resources>

Then you can get it from any page:

MediaElement player = null; // get the media element from App resources
if (App.Current.Resources.Contains("mediaPlayer"))
{
   player = App.Current.Resources["mediaPlayer"] as MediaElement;
}
if (player != null)
{
   player.Play();
}

MediaElement can’t play the music while Zune is connect, it is good to prompt the user about it.

if (NetworkInterface.GetIsNetworkAvailable())
{
   if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
   {
      zuneTextBlock.Visibility = System.Windows.Visibility.Visible;
      return;
   }
}
zuneTextBlock.Visibility = System.Windows.Visibility.Collapsed;

This code does not guarantee if Zune is on (User sill can have the plugged phone) but is very likely that Zune is running(Zune starts while you connect the phone).

Advertisements

A drab bunch – what does it mean?

The quote from Pro in WPF book:

“WPF applications would be a drab bunch if you were limited to the plain, gray look of ordinary buttons and other common controls. “

My first thought was “what does it mean?”. I’ve checked the dictionary – no help, then I’ve tried to google it which also didn’t give me the answer so I asked friend of mine form UK. He had no idea what it is. I was a little bit confused, whether it was a typo yet thanks to friend from U.S (Hi Gonzo) I have my answer.

it’s 1950s way to say boring or not happening, not cool group – beatnik stuff

Book writers should bare in mind that majority od developers are not U.S. based, shouldn’t they?

Some sophisticated content may not be understood.

whoa I got the e-mail from Matthew MacDonald himself.

“Drab” means “lacking color or liveliness” so the sentence “WPF applications would be a drab bunch …” means “WPF applications would be a dull, boring bunch of applications …” I assure you there’s no “beatnik” connection.

Perhaps the combination of clauses just made my sentence unnecessarily confusing?”

puzzle solved 😛

%d bloggers like this: