C#WPF如何重复从mediaended事件处理程序的MediaElement播放没有宣布新的来源? [英] c# WPF how to repeat MediaElement playback from mediaended event handler without declaring new source?

查看:1195
本文介绍了C#WPF如何重复从mediaended事件处理程序的MediaElement播放没有宣布新的来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM扮演WPF.i视频希望它循环,使我所做的是当mediaended事件触发,我播放我的视频。所以这会让我一个循环。概率是为什么ü我要再次创造新的来源?为什么不能我只是叫'玩'?

im playing a video in WPF.i want it to loop so what i did is when the mediaended event fires, i play back my video. so this will get me a loop. prob is why do u i have to create new source again? why cant i just call 'play'?

我不想做它在XAML是出于某种原因。

i dont want to do it in XAML as for some reason.

看看我的代码片段:

string startPath System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);


public Window1()
    {
        InitializeComponent();
        media.Source = new Uri(startPath + @"playlist.wpl");
        media.play();
    }

private void Media_Ended(object sender, EventArgs e)
    {
        media.Source = new Uri(startPath + @"playlist.wpl"); //if i dont put this line, video wont play..seems like it cant get the source
        media.Play();
    }



还是有一个正确的方法循环不在XAML,但在这里的.cs文件?

or is there a proper way to loop NOT in XAML but in here .cs file?

推荐答案

而不是在你Media_Ended处理程序的开始复位源,尝试设置位置值回起始位置。 position属性是一个时间跨度,所以你可能要像...

Instead of resetting the Source at the start of your Media_Ended handler, try setting the Position value back to the start position. The Position property is a TimeSpan so you probably want something like...

private void Media_Ended(object sender, EventArgs e)
{
    media.Position = TimeSpan.Zero;
    media.Play();
}

这篇关于C#WPF如何重复从mediaended事件处理程序的MediaElement播放没有宣布新的来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆