我们可用MediaPlayer控件做一个视频实时播放的实例,因为现在支持视频实时播放的软件较少,相信这段小程序能给你一些启发.
一.实现步骤
1.加入MediaPlayer控件,在部件中选择"控件"页的最后一项,并选中Windows Media Player即可
2.加入两个按钮控件:Command1,其Caption为"播放",Command2,其Caption为"回放"
3.加入一Timer控件,命名为Timer1,其Interval设为1000,Enabled为False
4.加入一CommonDialog控件,命名为cdg
二.代码
private Sub command1_click()
dim strTemp as string
cdg.filter="*.avi"
cdg.showopen
strTemp=cdg.filename
Timer1.enabled=false
Mediaplayer1.rate=1
Mediaplayer1.filename=strtemp
Mediaplayer1.play
FORM1.width=mediaplayer1.width+200
FORM1.left=mediaplayer1.left+50
FORM1.height=mediaplayer1.top+mediaplayer1.height+command1.height+600
command1.top=mediaplayer1.top+mediaplayer1.height+100
command2.top=command1.top
end sub
private sub command2_click()
mediaplayer1.pause
if mediaplayer1.displaymode<>mpFrames then
mediaplayer1.diaplaymode=mpFrames
end if
timer1.enabled=true
end sub
private sub timer1_timer()
timer1.interval=200
mediaplayer1.currentposition=mediaplayer1.currentposition-1
end sub