Adding xaml elements for VLC player to WPF application

寵の児 提交于 2019-12-25 01:09:51

问题


I am making a video game in C# WPF. I have a huge number of MediaElements, that run mp3 and mp4 files when needed. Recently I read that there is a license fee for just using those file formats, and decided to convert them to ogg and ogv formats.

Just to be sure you understand: I am not trying to make my own video player. I only need a way to run relevant files, at the correct stages of my game.

I found some information on the web, and now trying to make a small test app, that just runs a video on start.

I installed those NuGet plugins (didn't know which one is needed):

Meta.Vlc, Vlc.DotNet.Core, Vlc.DotNet.Core.Interops, Vlc.DotNet.Wpf

That's my xaml file:

 <Window x:Class="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:wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
    xmlns:local="clr-namespace:Test"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
    <MediaElement x:Name="movTest" Panel.ZIndex="1" HorizontalAlignment="Left" Height="319" Margin="10,0,0,0" VerticalAlignment="Top" Width="507" LoadedBehavior="Manual" Source="Resources/VideoFallingFromTable.ogv"/>
    <wpf:VlcControl x:Name="movTest2" Panel.ZIndex="2" />
</Grid>

Now, I see that there is no "Source" for wpf:VlcControl.

Si, I tried to load the source from MediaElement.

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {            
        movTest2.MediaPlayer.Play(movTest.Source);
    }

But I get just black window and no sound. I guess I am doing something wrong. Can you help me learn to run VLC player in WPF?

Thank you, Evgenie

UPDATE: I tried following code:

        VlcControl thisVlcControl = new VlcControl();
        Uri src = new Uri(movTest.Source.ToString(), UriKind.RelativeOrAbsolute);
        thisVlcControl.MediaPlayer.Play(src);

For some reason, it worked with mp4 file, but not with ogv.

来源:https://stackoverflow.com/questions/51101578/adding-xaml-elements-for-vlc-player-to-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!