none
MediaElement Windows 8 Phone app

    Question

  • 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);
       sound.Play();
    }

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

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

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

    Tuesday, January 29, 2013 12:02 AM

Answers

  • 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.


    -Eric.

    Wednesday, January 30, 2013 12:04 AM
    Owner