0

For one of my WPF projects I need to integrate VLC player and I have been playing around with the sample app from this Codeplex Project

However I need to create more than 1 instance of the the player control at runtime and display it setting its various properties. The number of player instances are based on user selection.

I am trying to convert the XAML given in the sample app to its equivalent code behind.

<Wpf:VlcControl x:Name="myVlcControl" />

<Grid Grid.Row="0">
     <Grid.Background>
         <VisualBrush Stretch="Uniform">
             <VisualBrush.Visual>
                 <Image Source="{Binding ElementName=myVlcControl, Path=VideoSource}" />
             </VisualBrush.Visual>
         </VisualBrush >
    </Grid.Background>
</Grid> 

This is what I have gotten to so far

EDIT: Code update after Chen Kinnrot's answer, but the problem persists.

    Grid g = new Grid();
    VlcControl p = new VlcControl();

    p.Media = new PathMedia(@"C:\movie.mkv");

    VisualBrush vbr = new VisualBrush();
    g.Background = vbr;

    vbr.Stretch = Stretch.Uniform;

    Binding binding = new Binding("VideoSource");
    binding.ElementName = "p";
    Image img = new Image();
    img.SetBinding(Image.SourceProperty, binding);

    vbr.Visual = img;
    g.Children.Add(p);                       
    this.grid1.Children.Add(g);
    p.Play();

With the above code behind, when I run the app I can hear the movie sound but not see it. I am missing the Image Binding (elementname and path) in my code behind, but don't know how to do it.

Can someone point me to some docs (Googling doesn't produce any good results) or provide pointers to convert the Binding in XAMl to its equivalent code behind?

Many Thanks

2
  • Have you tried creating multiple instances of the VLC control in XAML, to verify that it supports multiple instances? Commented Sep 17, 2011 at 19:14
  • @ HiredMind: yes it does support multiple instances. Commented Sep 17, 2011 at 19:50

2 Answers 2

1
        Binding binding = new Binding("VideoSource");
        binding.ElementName = "myVlcControl";
        Image img = new Image();
        img.SetBinding(Image.SourceProperty, binding);
Sign up to request clarification or add additional context in comments.

1 Comment

@ Chen Kinnrot: thank you so much for your answer. I have updated my code behind based on your answer, but still the problem persists, i.e I can hear the movie sound but cannot see the movie. Any further pointers?
1

I know this question is quite old, but I just encountered the same problem and thought to share the solution.

actually Chen Kinnrot's answer is quite complete, the only thing needed is to fix the binding.

instead of:

binding.ElementName = "myVlcControl";

it should be:

binding.Source = p; // p - the instance of the VlcControl

and combined with Chen code:

Binding binding = new Binding("VideoSource");
binding.Source = p;
Image img = new Image();
img.SetBinding(Image.SourceProperty, binding);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.