Gotcha: MediaElement AutoPlay faster than doing Play at MediaOpened
Just added the following comment to: https://github.com/loarabia/ManagedMediaHelpers/issues/15
Managed Media Helpers contains the very useful Mp3MediaSource class for .NET / Silverlight / Windows Phone.
Added compile-time SWITCHES and respective code to Silverlight demo code for PRELOAD (into memory stream) and AUTOPLAY (this was a bit tricky, need to call Play at MediaOpened event, not right after setting the source to the MediaElement).
Also seems to be 2-3 sec slower than AutoPlay (!) irrespective of using PRELOAD. Maybe it is faster to set the source again every time you want to play and just keep AutoPlay=true
Update: had a bug at the following code, obviously you first must set the MediaOpened event handler, then set the Source to the MediaPlayer. Also, one could set that handler once at the InitializeComponent method.
// <copyright file="Page.xaml.cs" company="Larry Olson">
// (c) Copyright Larry Olson.
// This source is subject to the Microsoft Public License (Ms-PL)
// See http://code.msdn.microsoft.com/ManagedMediaHelpers/Project/License.aspx
// All other rights reserved.
// Edited by George Birbilis (http://zoomicon.com)
/// A Page of a Silvelight Application.
public partial class Page : UserControl
/// Initializes a new instance of the Page class.
me.Volume = 1.0; //set max volume
me.AutoPlay = false;
me.MediaOpened += (s, e) =>
//me.Position = TimeSpan.Zero;
me.Stop(); //this stops current playback (if any) and rewinds back to start
//me.PlaybackRate = 1.0;
catch (Exception ex)
/// Event handler for the Button on the Page.
/// <param name="sender">
/// The button which was clicked.
/// <param name="e">
/// The state when this event was generated.
private void OpenMedia(object sender, RoutedEventArgs e)
OpenFileDialog ofd = new OpenFileDialog();
Stream data = ofd.File.OpenRead();
Stream m = new MemoryStream((int)ofd.File.Length);
m.Position = 0;
data = m;
Mp3MediaStreamSource mediaSource = new Mp3MediaStreamSource(data);