我正在尝试通过多个MediaElement控件播放视频。但是,当并排播放两个H.265时,只有一个(有时不播放)播放。然而,两个H.264视频并排播放完全没有问题。播放H.265视频所需的编解码器已经安装,并且视频可以在Windows Media Player中正常播放。
下面是一个非常简单的示例来演示我的问题:
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>只有同时播放视频时,才会出现这个问题。当我尝试一个接一个地播放视频(仍然使用不同的MediaElement)时,它仍然存在。这方面的任何帮助都是非常感谢的。
发布于 2017-05-05 17:40:14
尝试在该窗口中关闭硬件加速。我发现这解决了一个和你非常相似的问题。
将下面的代码放在您的主窗口中。
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);
}您可能还需要。
using System.Windows.Interop;https://stackoverflow.com/questions/41884017
复制相似问题