MediaEnded event not firing RRS feed

  • General discussion


    I am playing mp3-files with a MediaElement and the MediaEnded event is not firing every time.
    I found a post that it could happened if you try to play audio only files and have ScrubbingEnabled set to true so I set it to false but it still dose not fire the MediaEnded event.
    It seems to happen randomly. I don´t find any logic in this.


    • Changed type Marco Zhou Monday, July 21, 2008 10:28 AM OP doesn't revert back
    Monday, July 14, 2008 5:18 PM

All replies

  • I found out that the MediaElement never stops playing the sound. The duration just keeps on going and never stops to increase even thou the sound is very short (around one second)
    Anyone know what to do???

    Is there another way to play mp3 files. I have a clickonce application and I need to keep the trust level down as much as possible.


    Tuesday, July 15, 2008 2:15 PM
  • I cannot reproduce this problem, I use MediaPlayer to playback audio, if you don't play back video, you actually don't need to use MediaElement at all, here is my test code:

    mediaPlayer = new MediaPlayer();
    mediaPlayer.MediaEnded += delegate { MessageBox.Show("Media Ended"); };
    mediaPlayer.Open(new Uri(@"C:\biyege.mp3"));

    Thursday, July 17, 2008 3:56 AM
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by clicking the "Options" link at the top of your post, and selecting "Change Type" menu item from the pop menu. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


    Thank you!

    Monday, July 21, 2008 10:28 AM
  • I am having the same problem...

    Currently I have 11 mediaelements inside borders in my WPF application. (Silverlight 2 beta with visual studio 2008 and expression blend 2.5 june preview)

     All of them start up just fine and also, loop fine for the first couple of times...then a random mediaelement will freeze up. I currently am looking for the mediaended event to repeat playback...

    Here is my current code:
    Note:the event handler for all of the Mediaelements is ME_11_MediaEnded, all mes are set to manual on load, and the scrubbing is disabled

    .vb file
    Imports System 
    Imports System.IO 
    Imports System.Net 
    Imports System.Windows 
    Imports System.Windows.Controls 
    Imports System.Windows.Data 
    Imports System.Windows.Media 
    Imports System.Windows.Media.Animation 
    Imports System.Windows.Navigation 
    Partial Public Class Window1 
        Private zerospan As New TimeSpan(0, 0, 0) 
        Public Sub New() 
                ' Insert code required on object creation below this point. 
            Catch ex As Exception 
            End Try 
        End Sub 
        Private Sub StartAllMEs() 
        End Sub 
        Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
        End Sub 
        Private Sub ME_L11_MediaEnded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) 
            CType(sender, MediaElement).Position = zerospan 
            CType(sender, MediaElement).Play() 
        End Sub

    End Class 
    • Edited by slam121212 Saturday, August 2, 2008 4:31 AM for help
    Saturday, August 2, 2008 4:24 AM
  • I am also finding that the MediaEnded event is not being raised the way I expect it to. It is for me at least consistent though - if I create the MediaPlayer object in the same thread that owns the UI, it works. If I create the MediaPlayer object in a worker thread, it never raises the event or for that matter an exception to indicate a problem. I expect that restructuring the code to have the worker thread queue up media playback requests for the UI thread to actually trigger will be the only way to get the MediaEnded events to occur reliably.

    Wednesday, September 17, 2008 4:27 AM
  • Just in case someone reads this: The MediaPlayer events aren't fire probably because you don't have Dispatcher running in your worker thread.
    Monday, August 1, 2011 1:55 PM
  • How do I make sure Dispatcher is running ? I m instantiating a MEdiaElement object in the constructor and then

    registering the event but it doesn't seem to get called.

    	MainSong = ref new MediaElement();
    	MainSong->AutoPlay = false;
    	MainSong->MediaEnded  += ref new RoutedEventHandler(this, &Application2::BlankPage::StateChangedEventHandler);

    Sunday, March 11, 2012 4:38 AM