I have a problem with displaying videos in a grid using <MediaElement>
. I have made a separate class to get the video details with get set properties. Problem is i can't access the videos folder on window load when i debug the program. I have saved a folder named Videos in debug folder as well. If any one can help!! Thanks in advance.
VideoDetail.cs
public string Name { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string FileName { get; set; }
public string Extension { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public long Size { get; set; }
Window.xaml
<ItemsControl Name="VideoList" ItemsSource="{Binding VideoList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="#FFD0D1D7" Padding="5" Margin="10,10,0,0">
<StackPanel Orientation="Horizontal">
<!--image -->
<Grid Width="200" Height="150">
<MediaElement Source="{Binding Path}"/>
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Window.xaml.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string root = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string[] supportedExtensions = new[] { ".mp4" };
var files = Directory.GetFiles(Path.Combine(root, "Videos"), "*.*").Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower()));
List<ImageDetails> videos = new List<ImageDetails>();
foreach (var file in files)
{
ImageDetails id = new ImageDetails()
{
Path = file,
FileName = Path.GetFileName(file),
Extension = Path.GetExtension(file)
};
FileInfo fi = new FileInfo(file);
id.Size = fi.Length;
videos.Add(id);
}
VideoList.ItemsSource = videos;
}
}