简体   繁体   中英

WPF - MediaElements not displaying multiple H.265 videos

I am trying to play videos through multiple MediaElement controls. However, when playing two H.265 side by side, only one (or sometimes none) of them plays. However, two H.264 videos play side by side perfectly fine. The necessary codecs to play the H.265 video are already installed, and the videos play fine with Windows Media Player.

Here is a very simple example to demonstrate my problem:
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). 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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