有没有办法在Windows Media Control中重播视频?

时间:2010-12-07 18:57:32

标签: c# controls windows-media-player

如何在Windows Media控件中重播视频?我试着这样做吗?但它不起作用

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
        //mediaPlayer.currentPlaylist = mediaPlayer.mediaCollection.getByName("Dastan");
        //mediaPlayer.URL = @"C:\Documents and Settings\Администратор\Мои документы\Моя музыка\Мои списки воспроизведения\Dastan.wpl";
        //mediaPlayer.uiMode = "none";
        PlayFile(@"C:\Documents and Settings\Администратор\Мои документы\Моя музыка\Мои списки воспроизведения\Dastan.wpl");
    }

    private void mediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if ((WMPLib.WMPPlayState)e.newState == WMPPlayState.wmppsPlaying)
        {
            mediaPlayer.fullScreen = true;
            mediaPlayer.Ctlenabled = false;
        }
        else if ((WMPLib.WMPPlayState)e.newState == WMPPlayState.wmppsMediaEnded)
        {
            Form1_Load(null, null);
        }
    }
    private void PlayFile(String url)
    {
        mediaPlayer.URL = url;
        mediaPlayer.Ctlcontrols.play();
    }

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

mediaPlayer.settings.setMode("loop", true); 

此代码段完成所有工作。谢谢你的回答..

答案 1 :(得分:0)

尝试将mediaPlayer.Ctlcontrols.currentPosition设置为0。

private void mediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    if ((WMPLib.WMPPlayState)e.newState == WMPPlayState.wmppsPlaying)
    {
        mediaPlayer.fullScreen = true;
        mediaPlayer.Ctlenabled = false;
    }
    else if ((WMPLib.WMPPlayState)e.newState == WMPPlayState.wmppsMediaEnded)
    {
        mediaPlayer.Ctlcontrols.currentPosition = 0;
        mediaPlayer.Ctlcontrols.play();
    }
}