locked
find the media source??? RRS feed

  • Question

  • This was posted as a follow up question in another thread but I thought it would be more appropriate in it's own thread. 

    I'm making an app that dynamically loads different media files into a single media element. Click a button and a different media file loads. For certain reasons I am inserting the media files one of two different ways.

    The first way is:

    theMedia.Source = new Uri("intro.wmv", UriKind.Relative);

    The second way is upacking it (and a bunch of other files) from a downloaded zip using:

    StreamResourceInfo mediaResourceInfo = Application.GetResourceStream(zipResourceInfo, new Uri("gettingstarted.mp3", UriKind.Relative))
    this.theMedia.SetSource(mediaResourceInfo.Stream);

    All that is fine.

    Now I'm making a 'next' button. I've been trying to accomplish this by finding out which media file is loaded and taking the appropriate action based on that. So far I have:

    if (theMedia.Source.ToString().Contains("intro.wmv"))

    {
    Load the media file after 'intro.wmv'
    }

     
    which works for this first type but not the second, if I try:

    if (theMedia.Source.ToString().Contains("gettingstarted.mp3"))

    {
    Load the media file after 'gettingstarted.mp3'
    }

    I get the white screen of death.

    Anyone know how to accomplish this when the file loaded from a zip?

    Saturday, June 21, 2008 7:19 PM

Answers

  • So I made a demo project to upload for this thread. The thing about it though... it worked!

    I guess the reason that it wasn't working before is that I was trying to test against 'Source.Contains' and 'Tag'. Like this:

    if (theMedia.Source.ToString().Contains("intro"))

    {
    Load the media file after 'intro.wmv'
    }

     
    and

    else if ( theMedia.Tag.ToString() == "gettingstarted")

    {
    Load the media file after 'gettingstarted.mp3'
    }

     So I modified my project to use all 'Tag ==' and everything is working!

    Thanks all!

     


    Monday, June 23, 2008 7:40 PM

All replies

  • The behavior is expected because using SetSource function will leave the Source property (which is a Uri to the media file) to null, because you are setting the source through a stream not a URI. To solve your problem you can store the media file name in the tag property of your MediaElement, and test against it.
    Saturday, June 21, 2008 7:39 PM
  • Hmm, I've never used the tag property before. I tried setting using:

    this.theMedia.Tag = "gettingstarted";

     

    And testing against using: 

    else if (theMedia.Tag.ToString().Contains("gettingstarted")) 

     

    I didn't get any build errors but when I test it I get the white screen. What am I doing wrong here? 

    Sunday, June 22, 2008 6:45 PM
  • Since the last post I've also tried:

     

    else if ( theMedia.Tag.ToString() == "gettingstarted")

    and I get the same thing - no build errors but a white screen. Anyone know what I'm doing wrong here? 

     

    Monday, June 23, 2008 4:00 AM
  • I''m a bit confused here. the error seems like causing after changing the source.

    Are you changing the file while playing? If yes, please stop the media before changing source. if not, please try to set "null" before setting with another source.

    Monday, June 23, 2008 4:12 AM
  • Actually before the media changes it gets stopped and then set to null. Still the white screen persists. I'm stumped!

    Monday, June 23, 2008 4:38 AM
  • Hi:

      Could you post a demo project for us to reproduce this problem?

    Thanks

    Monday, June 23, 2008 6:39 AM
  • So I made a demo project to upload for this thread. The thing about it though... it worked!

    I guess the reason that it wasn't working before is that I was trying to test against 'Source.Contains' and 'Tag'. Like this:

    if (theMedia.Source.ToString().Contains("intro"))

    {
    Load the media file after 'intro.wmv'
    }

     
    and

    else if ( theMedia.Tag.ToString() == "gettingstarted")

    {
    Load the media file after 'gettingstarted.mp3'
    }

     So I modified my project to use all 'Tag ==' and everything is working!

    Thanks all!

     


    Monday, June 23, 2008 7:40 PM