Hi,@ Vishal2 Bansal. Welcome to Microsoft Q&A Forum.
To ensure smoother transitions between videos, you could try to set the MediaElement to be transparent during transitions.
<Grid Margin="50" Width="400" Height="200" HorizontalAlignment="Left" VerticalAlignment="Top">
<MediaElement x:Name="mediaElement" LoadedBehavior="Manual" MediaEnded="MediaElement_MediaEnded" />
</Grid>
Codebedhind:
private List<string> videoPaths = new List<string>
{
"C:\\...\\MediaElementDemo\\10MB_WMV.wmv" ,
"C:\\...\\MediaElementDemo\\20.wmv",
"C:\\...\\MediaElementDemo\\5MB_WMV.wmv"
};
private int currentVideoIndex = 0;
public MainWindow()
{
InitializeComponent();
PlayCurrentVideo();
}
private void PlayCurrentVideo()
{
var currentVideoPath = videoPaths[currentVideoIndex];
mediaElement.Source = new Uri(currentVideoPath, UriKind.RelativeOrAbsolute);
mediaElement.Play();
}
private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
CrossfadeToNextVideo();
}
private void CrossfadeToNextVideo()
{
var nextVideoIndex = (currentVideoIndex + 1) % videoPaths.Count;
var nextVideoPath = videoPaths[nextVideoIndex];
var fadeInDuration = TimeSpan.FromSeconds(1);
var fadeOutDuration = TimeSpan.FromSeconds(1);
var fadeOutAnimation = new DoubleAnimation(1, 0, fadeOutDuration);
fadeOutAnimation.Completed += (s, e) =>
{
mediaElement.Source = new Uri(nextVideoPath, UriKind.RelativeOrAbsolute);
mediaElement.Position = TimeSpan.Zero;
mediaElement.Play();
var fadeInAnimation = new DoubleAnimation(0, 1, fadeInDuration);
mediaElement.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
};
mediaElement.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
currentVideoIndex = nextVideoIndex;
}
The result:
Or you can also see if the solution here helps you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.