I'm working on a WPF desktop application, Windows 10, Visual Studio 2015.
In which when going to the location of the video is played, I have the following code.
XAML:
<Window x:Class="ReconocimientoVoz.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:local="clr-namespace:ReconocimientoVoz"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="28*"/>
<ColumnDefinition Width="19*"/>
</Grid.ColumnDefinitions>
<Rectangle x:Name="rectColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="55,46,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/>
<Label x:Name="lblColor" Content="lblColor" HorizontalAlignment="Left" Margin="144,234,0,0" VerticalAlignment="Top" Width="179" Grid.ColumnSpan="2"/>
<Button x:Name="btnEscuchar" Content="Escuchar" HorizontalAlignment="Left" Margin="62,234,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1" Click="btnEscuchar_Click"/>
<Label x:Name="label" Content="Color:" HorizontalAlignment="Left" Margin="98,234,0,0" VerticalAlignment="Top"/>
<MediaElement x:Name="mediaPlayer" Grid.Column="1" HorizontalAlignment="Left" Height="161"
Margin="0,35,0,0" VerticalAlignment="Top" Width="200" LoadedBehavior="Play"/>
</Grid>
In Mediaelement configure LoadedBehavior in Play so that supposedly at the moment of giving the video route can be displayed in the control.
C #
private void btnEscuchar_Click(object sender, RoutedEventArgs e)
{
lblColor.Content = string.Empty;
try
{
escucha.SetInputToDefaultAudioDevice();
escucha.LoadGrammar(new DictationGrammar());
//escucha.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(lector);
escucha.SpeechRecognized += Escucha_SpeechRecognized;
escucha.SetInputToDefaultAudioDevice();
escucha.RecognizeAsync(RecognizeMode.Multiple);
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message, "Aviso");
}
}
private void Escucha_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
foreach (var palabra in e.Result.Words)
{
lblColor.Content = palabra.Text;
if (palabra.Text == "rojo")
{
rectColor.Fill = new SolidColorBrush(Colors.Red);
}
else if (palabra.Text == "azul")
{
rectColor.Fill = new SolidColorBrush(Colors.Blue);
}
else if (palabra.Text == "amarillo")
{
rectColor.Fill = new SolidColorBrush(Colors.Yellow);
mediaPlayer.Source = new Uri(@"D:\PruebasCSharp\ReconocimientoVoz\Video\hola.wmv");
}
else if (palabra.Text == "hola")
{
mediaPlayer.Source = new Uri(@"D:\PruebasCSharp\ReconocimientoVoz\Video\hola.wmv");
//mediaPlayer.Play();
}
}
}
When the condition is met, it calls the video route but nothing is played on the MediaElement control.
I do not know what may be happening, does not reproduce anything? Do I need any extra configuration to the control or the form? I hope you can help me in advance thank you.
NOTE: I have done simple tests in which only it is programmed in the XAML and I have not been able to reproduce anything, that is why I think that some configuration must be missing in the control or in the window (form). I can only hear the audio of the video but it does not show the images.