MediaElement Windows 8 Phone app


  • I just wanna ask why when I put the mediaElementsource in the TapEvent the sound wouldn't play something like this:

    private void listBoxItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
       sound.Source = new Uri(@"Sounds/sample.mp3",UriKind.RelativeOrAbsolute);

    But when I Put the sound.Sorce outside the TapEvent the Sound is Played like this :

    public PageMusic()
          sound.Source = new Uri(@"Sounds/sample.mp3", UriKind.RelativeOrAbsolute);
    private void listBoxItem_GotFocus(object sender, RoutedEventArgs e)

    Is it a Bug or I'm doing something wrong or is it the emulator ??

    Tuesday, January 29, 2013 12:02 AM


  • Since you are explicitly calling Play(), I'm guessing you have AutoPlay=false... right?

    In that case you need to wait for the MediaOpened event before calling Play().

    It works in the second case because there is a significant delay between setting the source and calling Play but in the first case there is not enough time.


    Wednesday, January 30, 2013 12:04 AM