0

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.

EvgenieT
  • 209
  • 1
  • 4
  • 16
  • Did you read/try this? https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started – mm8 Jun 29 '18 at 12:44
  • I'll have a look, thanks! – EvgenieT Jun 29 '18 at 12:47
  • Again, there is too much of an information. All I want is to find out, how to open a video file, from my computer, specifically in my case. I am trying to research the issue, but there is simply too much of data. – EvgenieT Jun 29 '18 at 13:22
  • Did you call the `SetMedia` method to set the source of the player and then `Play()`? – mm8 Jun 29 '18 at 13:23
  • Yes, lie this: "VlcControl.MediaPlayer.SetMedia(movA.Source.ToString());" but I am getting this: "Object reference not set to an instance of an object.". ALso, for some reason, I can't even run MediaElement itself, unless I delete vlc from xaml. – EvgenieT Jun 29 '18 at 13:31
  • What is movA? Does it even have a Source? Debug your code to find out where the exception is thrown. – mm8 Jun 29 '18 at 13:37
  • MediaElement, with set source of video file. – EvgenieT Jun 29 '18 at 13:37
  • Now something starnge, what I was trying works with mp4, but no ogv. Will update question. – EvgenieT Jun 29 '18 at 13:45

0 Answers0