Making a MediaElement Loop

Posted: June 19, 2011 in Windows Phone 7 & Mango

You can make the MediaElement in Windows Phone 7 loop infinite times as follows:

public partial class MainPage : PhoneApplicationPage 
{ 
  public MainPage() 
  { 
    InitializeComponent(); 
    mediaElement1.Source = new Uri("YourMedia.wmv", UriKind.Relative); 
    mediaElement1.MediaEnded +=new RoutedEventHandler(mediaElement1_MediaEnded); 
  } 

  void mediaElement1_MediaEnded(object sender, RoutedEventArgs e) 
  { 
    mediaElement1.Position = TimeSpan.Zero;
    mediaElement1.Play(); 
  } 
} 
Advertisements
Comments
  1. Thanks! Now if I can only get the Windows Phone speech synthesizer to quit interrupting the background audio… 😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s