How to fade in/out between songs with a WPF C# mediaelement

偶尔善良 提交于 2019-12-11 21:12:14

问题


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.


回答1:


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




回答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.




回答3:


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.



来源:https://stackoverflow.com/questions/22500918/how-to-fade-in-out-between-songs-with-a-wpf-c-sharp-mediaelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!