Yesterday I posted thread about VLC player
and it's controls.
Adding xaml elements for VLC player to WPF application
After some time, I found a possible solution here:
Integrate VLC player in C# (WPF) project using Vlc.DotNet
I changed it just a little to fir my specific case:
Xaml:
<Window x:Class="WpfApp1.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:vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<vlc:VlcControl x:Name="vlcPlayer" />
<MediaElement x:Name="movOld" HorizontalAlignment="Left" Height="100" Margin="57,74,0,0" VerticalAlignment="Top" Width="100" Source="Resources/Global_Large_crate_opens.mp3"/>
</Grid>
Code:
public MainWindow()
{
InitializeComponent();
vlcPlayer.MediaPlayer.VlcLibDirectory = new DirectoryInfo(@"D:\VideoLAN\VLC\");
vlcPlayer.MediaPlayer.EndInit();
Uri thisUri = new Uri(@"C:\Users\User\Documents\Visual Studio 2017\Projects\WpfApp1\WpfApp1\Resources\VideoFallingFromTable.ogv", UriKind.RelativeOrAbsolute);
vlcPlayer.MediaPlayer.Play(thisUri);
}
This code works perfectly, when I give a full path from my computer.
However, for my game, I need to take the path from MediaElements
, like movOld
in this case.
However, when I try to do this:
Uri thisUri = new Uri(movOld.Source.ToString(), UriKind.RelativeOrAbsolute);
vlcPlayer.MediaPlayer.Play(thisUri);
I get this exception:
{"This operation is not supported for a relative URI."}
All my attempts to get file name, or file path as a string
, or to use "ToAbsolute()"
brought same extension.
Can someone please help me find where the error is, and how to fix it?
Since the game is to be used on many computers, with different possible installation places, it is of vital importance to load the new source for existing MediaElements
.