Why won't my MediaElement.MediaEnded event fire? RRS feed

  • Question

  • I'm trying to play multiple .mp3 tracks, and this would work by detecting when one track has ended and then starting the next.

    This works perfectly in my Windows Phone app, but isn't working in my Windows 8 port. The MediaElement.MediaEnded event is not firing.

    My code is in App.XAML.vb as I want this music available throughout the app (and this is how the phone version works

    I create my media element like this in the 'OnLaunched'

    MusicElement = New MediaElement
            AddHandler MusicElement.MediaEnded, AddressOf Element_MediaEnded

    and then have the handler:

     Private Sub Element_MediaEnded(ByVal sender As Object, ByVal args As RoutedEventArgs)
    End Sub

    Playback works fine, but the event doesn't get fired when the first track ends.

    Things I've tried:

    • Adding 'Handles MusicElement.MediaEnded to the handler declaration
    • Changing the MediaElement.AudioCategory (I hear that background enabled audio can cause the event to not fire)

    Any ideas what I'm doing wrong?

    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, August 8, 2013 3:23 AM

All replies