locked
MediaElement.MediaEnded does not fire when AudioCategory = AudioCategory.BackgroundCapableMedia RRS feed

  • Question

  • Hello, I've discovered that MediaEnded does not fire on MediaElement when AudioCategory = AudioCategory.BackgroundCapableMedia and the media is playing in the background. I rely on MediaEnded firing in order to support playlists and am wondering if this expected behavior or possibly a bug? If expected behavior, is there a workaround/alternate method to know when to start playing the next item in the playlist while the app is running in the background?

    Note: I have everything else setup in my app and am able to play my media in the background successfully (e.g. PlayControl events are wired and Audio Background Task is declared in the package manifest).

    Thanks, Tim

    Wednesday, December 5, 2012 8:09 PM

Answers

  • Hello all,

    I apologize for any inconvenience this issue may have caused. We are aware of this problem and currently considering possible solutions.

    A possible workaround may be to monitor the duration and current position for the end of the file. You should be able to do this without polling. Remember in most cases polling = bad.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 2, 2013 11:47 PM
    Moderator

All replies

  • Hi Tim,

    I am sorry that I can't reproduce your issue on my machine. The MediaEnded event is fired when I set the AudioCategory property to be "BackgroundCapableMedia". Here is the simple code I used on my side:

    <MediaElement x:Name="PlayRadio" MediaEnded="PlayRadio_MediaEnded_1" AudioCategory="BackgroundCapableMedia" Source="Assets/Wildlife.wmv"/>
    <TextBlock x:Name="RadioEnd"/>
    private void PlayRadio_MediaEnded_1(object sender, RoutedEventArgs e)
            {
                this.RadioEnd.Text = "The Radio is Ended...";
            }

    Could you please show me your sample code?

    Thanks.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 6, 2012 5:27 AM
    Moderator
  • Hi Vicky,

    The problem occurs when the application is in the background. Start playing the media element, switch the application to the background at least 10 seconds before the end of the track. The track keeps playing in the background for a little while until the end (because of BackgroundCapableMedia), and when the media ends, the MediaEnded event doesn't fire. It works however if I switch it to the background just 2 or 3 seconds before the end of the track.



    • Edited by Flavien C Thursday, December 6, 2012 10:31 AM
    Thursday, December 6, 2012 10:15 AM
  • Any update on that issue?

    Friday, December 7, 2012 8:43 PM
  • Hello,

    I can confirm this issue as well, exact same symptoms as described by Flavien C. 

    This topic is also being looked into @ http://playerframework.codeplex.com/discussions/405637 & http://playerframework.codeplex.com/discussions/409014

    Hoping this issue gets fixed soon.

    -Paul

    Thursday, December 20, 2012 4:06 PM
  • I think a solution might be to set a MediaMarker at the MediaOpened event (can't set one before that event) and use the MediaElement.NaturalDuration there to specify that the marker is at the end. When you get the MarkerReached event for that specific marker you can stop the mediaelement by code
    • Proposed as answer by ClipFlair Thursday, April 4, 2013 12:23 AM
    Thursday, April 4, 2013 12:23 AM
  • I am also seeing this issue. MediaEnded event is not fired when playing video in background. its always called when app is in foreground. 
    Sunday, April 14, 2013 4:20 AM
  • Vicky, here's a repro project.

    To duplicate:

    1. Run the app (from VS or deployed).
    2. Switch to another app (you need to do this before it gets within ~10 seconds from the end).
    3. Notice that you can successfully hear audio in the background.
    4. Wait until the video ends (it is a 30 second video and you can hear when it ends).
    5. Switch back to the app and notice that the text block does not show anything.

    Thanks, Tim

    Monday, April 22, 2013 7:16 PM
  • Hello all,

    I apologize for any inconvenience this issue may have caused. We are aware of this problem and currently considering possible solutions.

    A possible workaround may be to monitor the duration and current position for the end of the file. You should be able to do this without polling. Remember in most cases polling = bad.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 2, 2013 11:47 PM
    Moderator
  • I have the same problem. I've tried the workaround, detect the end of the file by the marker, it works, but playback of the next file never starts anyway, MediaElement opens the next file,  goes to the state "MediaElementState::Playing", but it never really starts playing, until the app is active. It simply behaves like in paused or suspended state (and Suspending event was not called yet).
    Tuesday, May 14, 2013 7:27 AM
  • Try using two MediaElements. You can also try setting the URI to NULL and then to the file you want to play.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, May 14, 2013 10:57 PM
    Moderator
  • Thanks, but no change. The problem seems to be more general - If I initiate video playback and minimalize application just before the playback starts (even for the first videofile), the behavior is the same - MediaElement loads the file, goes to the state MediaElementState::Playing, but never really starts playing, until the app is active again.
    Wednesday, May 15, 2013 6:47 AM
  • I remember at the WPF MediaElement that there are some properties regarding its automatic behaviour at Loat and at End of media. One could set it to Play again at the end for example (loop) with just a property.

    In case the Windows Phone one has such property try setting it to Manual instead

    Thursday, April 3, 2014 12:34 PM