locked
AutoPlay media element without source RRS feed

  • Question

  • When I made a media element without source in xaml, set AutoPlay to false. After a while i set a source for my media element and set auto play true in code behind but it didn't work.

     

    So If you want to  set source  in runtime DO NOT SET AUTOPLAY FALSE IN XAML

    Monday, February 9, 2009 3:36 AM

Answers

  • problem is "mediaelement  is not ready"
    so...

    MediaElement media = new MediaElement();
    media .MediaOpened += new RoutedEventHandler(mediaelement_mainvideo_MediaOpened);
    media .Source = new Uri("<media path>", UriKind.RelativeOrAbsolute);

    void mediaelement_mainvideo_MediaOpened(object sender, RoutedEventArgs e)
    {
          media.AutoPlay = false;
    }

     

    you must add "Media Opened Event"...

     

    Monday, February 9, 2009 3:47 AM