WPF MediaElement,如何让重复更慢?

时间:2016-03-01 04:43:47

标签: wpf

每次重复都会延迟。

let mediaTimeline=MediaTimeline(Source=Uri@"...mp3",RepeatBehavior=RepeatBehavior.Forever)
let storyboard=Storyboard()
storyboard.Children.Add mediaTimeline
let mediaElement=MediaElement()
mediaElement.BeginStoryboard<|storyboard

(欢迎使用任何语言或WPF标记答案)

1 个答案:

答案 0 :(得分:2)

你可以这样做:

using System.Threading.Tasks;

MediaElement me = new MediaElement(); // Make sure add this control to Window or a control.

me.MediaEnded += me_MediaEnded;
me.LoadedBehavior = MediaState.Manual;  // Must have this line
// load song...
me.Play();


async void me_MediaEnded(object sender, RoutedEventArgs e)
{
    await Task.Delay(1000);
    me.Play();
}

注意:await需要.Net 4.5。如果您的.Net文字较低,则可以使用DispatcherTimer代替。