Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Set mediaelement source in managed code RSS

2 replies

Last post Jul 06, 2007 06:53 PM by djmiller9975

(0)
  • djmiller9975

    djmiller9975

    Member

    2 Points

    2 Posts

    Set mediaelement source in managed code

    Jul 06, 2007 06:44 PM | LINK

    Hi, I've created a Silverlight project in Orcas and created my own media player user control that includes a media element.  I now include the custom control in another xaml page and want to set the media element source via the managed code behind the main xaml page or even in the xaml page when the custom control is declared.

     I added a public property to my custom control for the source, but the media element is looking for a uri for the source.  Somehow the xaml is converting the relative uri to an absolute one and I can't get the application to work on my local machine.  Is there a way to get the base uri of the application and append the name of the video file to create an absolute uri?

    dim myURI as new URI(app.path & "myvideofile.wmv")  app.path isn't available in a Silverlight application.  Heres the property from my custom control.

     Public Property Source() As String

    Get

    Return m_mediaSource

    End Get

    Set(ByVal value As String)Dim tURI As New Uri(mybaseuri & "/" & value)

    m_mediaSource = value

    m_media.Source = tURI

    End Set

    End Property

    The page loads, but never loads the video file.  Any ideas of how to set the source via managed code?

  • Bill Reiss

    Bill Reiss

    Contributor

    4973 Points

    947 Posts

    Re: Set mediaelement source in managed code

    Jul 06, 2007 06:50 PM | LINK

    There's another Uri constructor which takes a UriKind as the second parameter. Specify a UriKind of Relative and it should do what you want.


    Bill Reiss, Coauthor of Hello! Silverlight
    My blog
  • djmiller9975

    djmiller9975

    Member

    2 Points

    2 Posts

    Re: Set mediaelement source in managed code

    Jul 06, 2007 06:53 PM | LINK

    After further testing, I found that I can set the property using a fully qualified uri but not a relative one.  If you have any idea how to set this using a releative uri I would appreciate it.

     Thanks,