开发者

Playing video in Silverlight with Source binding

开发者 https://www.devze.com 2023-04-11 07:23 出处:网络
I am trying to make a WMV video to play in Silverlight MediaElement. It works in this XAML code: <MediaElement

I am trying to make a WMV video to play in Silverlight MediaElement. It works in this XAML code:

        <MediaElement
        x:Name="VideoElement"
        Stretch="Fill"
        Source=""http://ecn.channel9.msdn.com/o9/pdc09/wmv/CL20.wmv""
        Grid.Row="0"
        Grid.Column="0"
        AutoPlay="True"/>

But when I try to bind the source to some property in my code like this:

        <MediaElement
        x:Name="VideoElement"
        Stretch="Fill"
        Source="{Binding VidPath}"
        Grid.Row="0"
        Grid.Column="0"
        开发者_如何学编程AutoPlay="True"/>

Where VidPath is:

    public Uri VidPath
    {
        get
        {
            return new Uri("http://ecn.channel9.msdn.com/o9/pdc09/wmv/CL20.wmv", UriKind.Absolute);
        }
        set;
    }

It doesn't work. Can you help me figure out why?


First, I'll assume this is an out of browser application with full trust, otherwise cross-domain policy restrictions would prevent the MediaElement from playing that video either way.

Given that, there's nothing wrong with the code you've supplied, but I have a hunch the DataContext of the page that contains your MediaPlayer isn't set correctly. If you put a breakpoint in the getter for VidPath, does it ever get hit? I'm betting no.

Whatever object contains your "VidPath" property, you want to make sure that's the DataContext of your page. E.g. if you just put VidPath as a property in the code-behind, you can add this to the constructor:

this.DataContext = this;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号