简体   繁体   English

WPF-MediaElements不显示多个H.265视频

[英]WPF - MediaElements not displaying multiple H.265 videos

I am trying to play videos through multiple MediaElement controls. 我正在尝试通过多个MediaElement控件播放视频。 However, when playing two H.265 side by side, only one (or sometimes none) of them plays. 但是,当同时播放两个H.265时,它们中只有一个(有时没有)播放。 However, two H.264 videos play side by side perfectly fine. 但是,两个H.264视频可以并排播放。 The necessary codecs to play the H.265 video are already installed, and the videos play fine with Windows Media Player. 已经安装了播放H.265视频所需的编解码器,并且这些视频可以在Windows Media Player中正常播放。

Here is a very simple example to demonstrate my problem: 这是一个非常简单的示例来演示我的问题:
XAML: XAML:

<Window x:Class="Wpf.Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Wpf.Test"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <MediaElement Name="video_1" Source="C:\Users\public\Videos\test_vid_1.mp4" LoadedBehavior="Play" />
        <MediaElement Name="video_2" Source="C:\Users\public\Videos\test_vid_2.mp4" LoadedBehavior="Play" Grid.Column="1" />
    </Grid>
</Window>

This problem doesn't exist only when the videos are attempted to be played at the same time. 仅当尝试同时播放视频时才存在此问题。 It still persists when I try to play one video after the other (still using the different MediaElement s). 当我尝试播放一个视频又播放另一个视频时,它仍然存在(仍然使用其他MediaElement )。 Any help with this is greatly appreciated. 任何帮助,我们将不胜感激。

Try turning off hardware acceleration in that window. 尝试在该窗口中关闭硬件加速。 I found this to solve a problem very similar to yours. 我发现这可以解决与您非常相似的问题。

Place the code below in your main window. 将下面的代码放在主窗口中。

protected override void OnSourceInitialized(EventArgs e)
{
    // For added compatibility, turn off hardware rendering 
    HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
    HwndTarget hwndTarget = hwndSource.CompositionTarget;
    hwndTarget.RenderMode = RenderMode.SoftwareOnly;
    base.OnSourceInitialized(e);
}

You may also need. 您可能还需要。

using System.Windows.Interop;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM