我有一个关于WPF中多个MediaElement的问题。我想在同一时间只播放一个MediaElement,直到音频索引改变。声源只是一个短语,所以我会重复/循环它。但问题是,它会在一段时间后停止播放。有谁能帮帮我吗?
以下是一些代码:
*.xaml
以下是一些代码:
*.xaml
<MediaElement x:Name="mediaElementStrawberries" LoadedBehavior="Manual" UnloadedBehavior="Manual" MediaEnded="mediaElementStrawberriesEnded" Source="Media\Strawberries.mp3"/>
<MediaElement x:Name="mediaElementBlackberries" LoadedBehavior="Manual" UnloadedBehavior="Manual" MediaEnded="mediaElementBlackberriesEnded" Source="Media\Blackberries.mp3"/>
<MediaElement x:Name="mediaElementBlueberries" LoadedBehavior="Manual" UnloadedBehavior="Manual" MediaEnded="mediaElementBlueberriesEnded" Source="Media\Blueberries.mp3"/>
*.cs
if (audioindex == 1)
{
mediaElementStrawberries.Play();
}
if (audioindex == 2)
{
mediaElementBlackberries.Play();
}
if (audioindex == 3)
{
mediaElementBlueberries.Play();
}
public void mediaElementStrawberriesEnded(object sender, RoutedEventArgs e)
{
if (audioindex == 1)
{
mediaElemenStrawberries.Position = TimeSpan.Zero;
mediaElementStrawberries.LoadedBehavior = MediaState.Play;
}
else if (audioindex == 2)
{
mediaElementBlackberries.Position = TimeSpan.Zero;
mediaElementBlackberries.LoadedBehavior = MediaState.Play;
}
else if (audioindex == 3)
{
mediaElementBlueberries.Position = TimeSpan.Zero;
mediaElementBlueberries.LoadedBehavior = MediaState.Play;
}
}
private void mediaElementBlackberriesEnded(object sender, RoutedEventArgs e)
{
if (audioindex == 2)
{
mediaElementBlackberries.Position = TimeSpan.Zero;
mediaElementBlackberries.LoadedBehavior = MediaState.Play;
}
else if (audioindex == 1)
{
mediaElementStrawberries.Position = TimeSpan.Zero;
mediaElementStrawberries.LoadedBehavior = MediaState.Play;
}
else if (audioindex == 3)
{
mediaElementBlueberries.Position = TimeSpan.Zero;
mediaElementBlueberries.LoadedBehavior = MediaState.Play;
}
}