将WPF MediaElement视频与第二个窗口同步 [英] Synchronize WPF MediaElement Video with second window

查看:159
本文介绍了将WPF MediaElement视频与第二个窗口同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经在Stackoverflow上问过了,但是没有任何答案,非常抱歉. 也许我们可以在这里废弃它.
我正在使用WPF MediaElement和OnButton播放视频,单击它会打开第二个窗口(我使用Screens.AllScreens [1]将其移动到第二个监视器).在第二个窗口中,我创建了一个新的mediaelement实例,并将值从mediaelement1.position放入mediaelemnt2.position.现在我在第二个窗口中有一秒钟的延迟...

有办法解决吗?

感谢您的帮助.

Hi,

I''ve already asked at Stackoverflow, but without any answers, so sorry for double post.
Maybe we can disuss it here.
I''m playing a video with the WPF MediaElement and OnButton Click it opens a second window (I move it with Screens.AllScreens[1] to my second monitor). On second window I''ve created a new instance of mediaelement and put the value from mediaelement1.position to mediaelemnt2.position. Now I have a one second delay in my second window ...

Is there a way to handle this?

Thanks for help

推荐答案

首先,您真的不想多次解码和播放电影,因此您应该找到另一种解决方案.而且,如果不对元素后面的代码进行一些重大更改,那么第二个元素的同步是不可能的,我们不能真正改变它.

所以,你可以做什么?好吧,实际上这很简单,所以我很惊讶您之前还没有收到响应.
您要做的是将MediaElement放在VisualBrush中,然后在要显示电影的任何地方显示该Brush.

这是一个示例实现
Window1.xaml
First of you don''t really want to decode and play the movie more than once, so you should find another solution. And second syncronizing the two elements is impossible without making some serious changes to the code behind the element and we can''t really change that.

So what can you do? well it''s quite simple actually, so I''m surprised you haven''t recieved a response before now.
What you want to do is put the MediaElement in a VisualBrush and then display that Brush where ever you want to display the movie.

Here is a sample implementation
Window1.xaml
<Window ...>
    <Window.Resources>
        <VisualBrush x:Key="Media" Stretch="Uniform">
            <VisualBrush.Visual>
                <MediaElement Source="PathToMedia"/>
            </VisualBrush.Visual>
        </VisualBrush>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Rectangle Fill="{StaticResource Media}"/>

        <Button Click="Button_Click" Grid.Row="1" Content="Click me!"/>
    </Grid>
</Window>



Window1.xaml.cs



Window1.xaml.cs

private void Button_Click(object sender, RoutedEventArgs e)
{
    new Window2(Resources["Media"] as VisualBrush).Show();
}



Window2.xaml



Window2.xaml

<Window ...>
    <Rectangle Name="display"/>
</Window>



Window2.xaml.cs



Window2.xaml.cs

public Window2(VisualBrush visualBrush)
{
    InitializeComponent();

    display.Fill = visualBrush;
}


这篇关于将WPF MediaElement视频与第二个窗口同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆