locked
Going back from a page with a MediaElement RRS feed

  • Question

  • Hello,

    I am playing a video in a MediaElement but when I try to navigate back (to the previous page), firstly the video restarts and when I try again, the application exits.
    I tried to navigate by two methods : by tapping the hardware button, and by tapping a button in the application.
    I also stopped the video, before going back.

    If you already have this problem, tell me some indications. Thank you.
    Monday, June 18, 2012 1:33 PM

All replies

  • I am playing a video in a MediaElement
    How?
    Monday, June 18, 2012 3:03 PM
  • The video is played from a remote url, and the source is set in the code-behind. The video plays correctly.
    Monday, June 18, 2012 3:34 PM
  • the source is set in the code-behind.
    Sharing the relevant code might be a good thing. :\
    Monday, June 18, 2012 7:42 PM
  • Sure.

    Here I launch the player, with an element contained in my list : (I have no problem to play the video)
    player.Source = ElementList[CurrentElementNumber].Source; // it contains a remote url (http://192.168.1.111:8080/streaming/300_low.mov)
    player.Play(); 

    I go back using this :
    player.Stop();
    NavigationService.GoBack(); 

    I have the same problem if I try to navigate to another page of the application.
    Tuesday, June 19, 2012 7:26 AM
  • Although I don't have a solution to your problem. I'd like to make a suggestion:

    Instead of:
    NavigationService.GoBack();
    use
    if (NavigationService.CanGoBack()) {
    NavigationService.GoBack();
    }

    it'll prevent from crashing when somehow an history navigation has been deleted/lost/disappeared.
    (code might contain some errors like wrong uppercase usage, didn't test it)
    Tuesday, June 19, 2012 9:02 AM
  • I just tried. The CanGoBack boolean is true, so the behaviour of the app is still the same.

    Actually, the previous page appears like 0.5 seconds and then it goes to the menu.
    Tuesday, June 19, 2012 12:45 PM
  • Actually, the previous page appears like 0.5 seconds and then it goes to the menu.
    Then you're doing something else that you're not showing us. 4 lines of code can't be all the relevant code. 
    Tuesday, June 19, 2012 1:43 PM
  • when I try to navigate back (to the previous page), firstly the video restarts
    Do you mean that the video simply restarts and the page doesn't navigate? It's something that your code is doing, not caused by MediaElement.

    Build a test app that simply opens MediaElement on a second page. It should be able to go back to the first page.


    Richard Woo
    Tuesday, June 19, 2012 3:33 PM
  • My code is maybe too long to post it here.
    If you say so, the problem doesn't come from the MediaElement. I will look in details where I am doing wrong...

    Thanks.
    Wednesday, June 20, 2012 3:55 PM
  • Do you have more than one page with a MediaElement?  (ex: MainPage.xaml and Page1.xaml)
    ( ... or maybe two (or more) instance of the same page?)

    Do you have any other code which touches the RootFrame, RootVisual, or NavigationSevice.BackStack?

    Wednesday, June 20, 2012 9:30 PM
  • I have a MainPage where I am including UserControl depending on the parameters I have put in the Url.

    The two pages I want to browse are the following :

    /MainPage.xaml?page=media (here I call the second page)

    /MainPage.xaml?page=videoplayer (containing the MediaElement, and going back to the first one)

    Edit : Actually the problem was from a call to :
    BackgroundAudioPlayer.Instance.Track != null 
    At the call of the first page, it doesn't throw an exception.
    But creating a MediaElement disables the BackgroundAudioPlayer, and its properties cannot be used again (not even read).
    Thursday, June 21, 2012 12:51 PM
  • OK, I was able to see this somewhat in a quick sample I threw together. I saw the video start again when press either the hardware Back or a button in the app to navigate backwards, but the navigation did happen. I didn't have to press Back more than once.
    Thursday, June 21, 2012 4:05 PM
  • Edit : Actually the problem was from a call to :
    BackgroundAudioPlayer.Instance.Track != null 
    At the call of the first page, it doesn't throw an exception.
    But creating a MediaElement disables the BackgroundAudioPlayer, and its properties cannot be used again (not even read).

    Yes, there is only one media queue so MediaElement and BackgroundAudioPlayer both compete for access.

    This is mentioned in the Background Audio Overview topic in the docs:
    MediaElement and the BackgroundAudioPlayer

    Care must be taken when mixing BackgroundAudioPlayer and MediaElement for audio playback.

    1. Close() must be called before switching to MediaElement playback.

    2. There is only one media queue. Your application cannot pause background audio, play something with MediaElement then resume the background audio stream.


    Thursday, June 21, 2012 4:52 PM