为什么 WPF MediaElement 在辅助监视器上不起作用? [英] Why does WPF MediaElement not work on secondary monitor?

查看:27
本文介绍了为什么 WPF MediaElement 在辅助监视器上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用 WPF MediaElement 播放视频(MOV 文件).这在主显示器上播放时效果很好,但当窗口移动到辅助显示器时会冻结.

My application uses the WPF MediaElement to play video (MOV files). This works well when playing on the Primary monitor but freezes when the window is moved to the secondary monitor.

我尝试了以下方法但没有成功:

I have tried the following without success:

  1. 在辅助监视器上启动应用程序
  2. 交换主要 &辅助监视器(问题转移到新的辅助监视器)

当应用程序窗口跨越两台显示器时,它可以正常工作,但一旦它完全位于辅助显示器内,视频就会冻结.进入这种状态后,将应用程序移回主监视器无济于事(加载新视频也无济于事).

When the application window spans both monitors it works correctly but as soon as it is entirely within the secondary monitor the video freezes. Once in this state, moving the application back to the primary monitor doesn't help (and loading a new video doesn't help either).

显示器的排列使得坐标始终为正(两个显示器都是 1920x1080,辅助显示器原点是 1920,0).

The monitors are arranged so that the co-ordinates are always positive (both monitors are 1920x1080 and the secondary monitor origin is 1920,0).

有没有其他人看到过这个问题和/或找到了解决方法?

Has anyone else seen this problem and/or found a fix?

编辑

是否有人将 WPF MediaElement 与多个显示器一起使用???

Does anyone use the WPF MediaElement with multiple monitors???

推荐答案

这仍然是 .NET Framework 4.0 中的一个已知问题,MS 将其描述为 该问题发生在同步时当显示发生变化时,WPF 和底层 WMP 控件之间必须重新同步." H.264 编解码器视频文件发生这种情况.

This is still a known issue in .NET Framework 4.0, which MS described as "The issue occurs when a synchronization between WPF and the underlying WMP control have to resynchronize when the display changes occur." It happens to H.264 codec video files.

这里有 3 种解决方法.

Here are 3 workarounds.

1 .对包含 MediaElement 控件的窗口使用软件渲染

private void Window_Loaded(object sender, RoutedEventArgs e)
{
        var hwndSource = PresentationSource.FromVisual(this) as HwndSource;
        if (hwndSource != null)
        {
            var hwndTarget = hwndSource.CompositionTarget;
            if (hwndTarget != null) hwndTarget.RenderMode = RenderMode.SoftwareOnly;
        }
}

然而,这并没有利用 GPU 和图形内存,可能会降低视频播放速度.

However this is not utilizing the GPU and graphics memory and could slow down the video playback.

2.与主显示器重叠至少 1 个像素

例如,假设主屏幕在左侧,并且 MediaElement 填满了整个窗口.在窗口的构造函数中,假设 Rect bounds 代表二级监视器边界,使用

For example, suppose the primary screen in on the left, and the MediaElement fills the entire window. In the window's constructor, suppose Rect bounds represents the secondary monitor boundary, use

this.Left = bounds.Left - 1;
this.Width = bounds.Width;
this.Top = bounds.Top;
this.Height = bounds.Height;

所以 MediaElement 在主显示器上有 1 像素宽的重叠,然后它就可以正常播放 H.264 视频文件.

so the MediaElement has 1 pixel wide overlapped on the primary monitor, and then it's able to play H.264 video files normally.

3.使用 MS Media Foundation 编解码器以外的其他 MP4 编解码器

下载工具Win7DSFilterTweaker"以禁用媒体基础MP4"播放.安装另一个 MP4 编解码器,例如 ffshow.

Download a tool "Win7DSFilterTweaker" to disable Media Foundation "MP4" playback. Install another MP4 codec, ffshow, for example.

这篇关于为什么 WPF MediaElement 在辅助监视器上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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