title: Trouble with MediaElement in Silverlight
body: <p>I'm having difficulty with the <code>MediaElement</code> control in Silverlight for Windows Phone 7. My goal is to play two tones when the user presses a button. The method of doing this that I came up with is to have a <code>MediaElement</code> for each tone. (Is there possibly a better way?)</p>
  
  <pre><code>&lt;phone:PhoneApplicationPage 
      x:Class="MediaElementTest.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
      xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
      FontFamily="{StaticResource PhoneFontFamilyNormal}"
      FontSize="{StaticResource PhoneFontSizeNormal}"
      Foreground="{StaticResource PhoneForegroundBrush}"
      SupportedOrientations="Portrait" Orientation="Portrait"
      shell:SystemTray.IsVisible="True"&gt;
  
      &lt;StackPanel x:Name="LayoutRoot" Background="Transparent"&gt;
  
              &lt;MediaElement 
                  x:Name="firstTone"
                  MediaEnded="firstTone_MediaEnded"
                  Source="{Binding FirstTone}" /&gt;
              &lt;MediaElement 
                  x:Name="secondTone"
                  Source="{Binding SecondTone}" /&gt;
              &lt;Button Content="Play" Click="Button_Click" /&gt;
  
      &lt;/StackPanel&gt;
  
  &lt;/phone:PhoneApplicationPage&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>public partial class MainPage : PhoneApplicationPage
      {
          public Uri FirstTone
          {
              get
              {
                  return new Uri("A.mp3", UriKind.Relative);
              }
          }
  
          public Uri SecondTone
          {
              get
              {
                  return new Uri("B.mp3", UriKind.Relative);
              }
          }
  
          public MainPage()
          {
              InitializeComponent();
              LayoutRoot.DataContext = this;
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              firstTone.Stop();
              secondTone.Stop();
  
              firstTone.Play();
          }
  
          private void firstTone_MediaEnded(object sender, RoutedEventArgs e)
          {
              secondTone.Play();
          }
      }
  </code></pre>
  
  <p>When I click the button, no tone plays. Why is this? What am I doing wrong?</p>