c# - Start and stop video Windows Media Player at specific times -
i using windows media player object playing video in c# winforms project.
videoplayer.url = "c:\test.avi";
my test.avi duration 12 seconds. play between 4 , 8 seconds.
i can start video 4 second below;
videoplayer.ctlcontrols.currentposition = 4
so how can stop video 8th seconds after playing video?
you can use timer so:
private timer tmrwmpplayerposition; private timespan stopposition; private void btn_click(object sender, eventargs e) { wmpplayer.ctlcontrols.currentposition = 4; stopposition=timespan.parse("00:20:20"); stopwmpplayertimer(); startwmpplayertimer(); } private void tmrwmpplayerposition_tick(object sender, eventargs e) { if ((convert.toint32(stopposition.totalseconds) != convert.toint32(wmpplayer.ctlcontrols.currentposition))) return; wmpplayer.ctlcontrols.pause(); stopwmpplayertimer(); } private void startwmpplayertimer() { tmrwmpplayerposition = new timer(); tmrwmpplayerposition.tick += new eventhandler(tmrwmpplayerposition_tick); tmrwmpplayerposition.enabled = true; tmrwmpplayerposition.interval = 1000; tmrwmpplayerposition.start(); } private void stopwmpplayertimer() { if (tmrwmpplayerposition != null) tmrwmpplayerposition.dispose(); tmrwmpplayerposition = null; }
Comments
Post a Comment