Answer the question
In order to leave comments, you need to log in
WPF How to set play button to specific video?
Hello =)
Can someone tell me how to set the buttons to play different videos in MediaElement? something like this >>>
Thanks in advance)
Answer the question
In order to leave comments, you need to log in
On click, change src and start the player like this
using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (sender is Button btn)
{
MediaControl.LoadedBehavior = MediaState.Manual;
MediaControl.Source = new Uri($"video/{btn.Name}.mp4", UriKind.Relative);
MediaControl.Play();
}
}
}
}
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<MediaElement Grid.Row="0" Height="200" Width="300" Name="MediaControl"></MediaElement>
<Button Grid.Row="1" Click="ButtonBase_OnClick" Name="Btn1">one</Button>
<Button Grid.Row="2" Click="ButtonBase_OnClick" Name="Btn2">two</Button>
<Button Grid.Row="3" Click="ButtonBase_OnClick" Name="Btn3">three</Button>
</Grid>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question