1

I am writing a media player and I'm using WPF in C#.

My problem is that I have no idea of how to create a fade in/ fade out function (using the media element), meaning that the last 7 seconds of the playing song will start to fade out and at the same time the first 7 seconds of the next song will start to play.

Has anyone done this? If so, then can someone please help me? Thank you.

ouflak
  • 2,458
  • 10
  • 44
  • 49

3 Answers3

2

you can animate the UIElement.Opacity property to achieve video fading...

Here is a link for fading the video http://www.darinhiggins.com/fading-two-video-windows-in-wpf/

Similarly for fading the audio, you could animate the MediaElement.Volume property.

Suresh Kumar Veluswamy
  • 4,193
  • 2
  • 20
  • 35
2

You could put a trigger on MediaElement.Position that starts a DoubleAnimation on MediaElement.Volume when within seven seconds of the end (MediaElement.NaturalDuration)

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
1
myMediaElement.Play();
myMediaElement.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(myMediaElement.Opacity, 0, TimeSpan.FromSeconds(10)));
myMediaElement.BeginAnimation(MediaElement.VolumeProperty, new DoubleAnimation(myMediaElement.Volume, 0, TimeSpan.FromSeconds(11)));

myMediaElement1.Play();
myMediaElement1.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(myMediaElement1.Opacity, 1, TimeSpan.FromSeconds(10)));
myMediaElement1.BeginAnimation(MediaElement.VolumeProperty, new DoubleAnimation(myMediaElement1.Volume, 1, TimeSpan.FromSeconds(11)));

Hope this helps.. Just create two MediaElements, works for volume, and visual.

Max Mazur
  • 1,188
  • 1
  • 13
  • 22