J'ai un problème avec le contrôle MediaElement. J'ai mis six MediaElements sur mon formulaire, puis je les démarre et change les fichiers lus par minuteur. Après plusieurs fois, ces éléments cessent de jouer.MediaElement échoue après plusieurs lectures
Voici l'exemple XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<MediaElement x:Name="element1" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="0" Grid.Row="0" />
<MediaElement x:Name="element2" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="1" Grid.Row="0" />
<MediaElement x:Name="element3" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="2" Grid.Row="0" />
<MediaElement x:Name="element4" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="0" Grid.Row="1" />
<MediaElement x:Name="element5" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="1" Grid.Row="1" />
<MediaElement x:Name="element6" UnloadedBehavior="Close" LoadedBehavior="Manual" Grid.Column="2" Grid.Row="1" />
Voici l'exemple de code:
// The code below repeats for each MediaElement
List<string> playlist1 = new List<string>()
{
@"file1.wmv",
@"file2.wmv",
@"file3.wmv",
@"file4.wmv"
};
DispatcherTimer timer1 = null;
int index1 = 0;
...
void Window1_Loaded(object sender, RoutedEventArgs e)
{
timer1 = new DispatcherTimer();
timer1.Tick += new EventHandler(timer1_Elapsed);
timer1.Interval = TimeSpan.FromSeconds(10);
element1.Source = new Uri(playlist1[index1]);
timer1.Start();
element1.Play();
...
}
void timer1_Elapsed(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate()
{
element1.Stop();
element1.Close();
timer1.Stop();
index1++;
if (index1 >= playlist1.Count)
{
index1 = 0;
}
element1.Source = new Uri(playlist1[index1]);
timer1.Start();
element1.Play();
});
}
...
Est-ce que quelqu'un a des problèmes similaires?