c# winform DirectX播放器 可以任意设置宽高比 屏幕拉伸

第一步:dll引用

Microsoft.DirectX.dll

Microsoft.DirectX.AudioVideoPlayback.dll

如果没有的话,可能需要安装微软的DRECTX JDK

directx支持的视频文件格式: (*.avi; *.mov; *.mpg; *.mpeg; *.ts; *.wmv; *.vob; *.dat; *.rm; *.rmvb; *.flv)|*.avi; *.mov; *.mpg; *.mpeg; *.ts; *.wmv; *.vob; *.dat; *.rm; *.rmvb; *.flv";

第二步:开发代码

ourVideo = new Video(fileName);//视频文件路径
                    ourVideo.Ending += new EventHandler(ourVideo_Ending);//注册视频播放完成事件
                    ourVideo.Owner = this.picPlayWindow;//指定播放媒介pictureBox

                    
                    ourVideo.Play();

                    duration = ourVideo.Duration;

private Video ourVideo = null;

ourVideo.Stop();

ourVideo.Dispose();

ourVideo.Fullscreen = true;

第三步:设定屏幕拉伸和宽高比

这个的设定是,通过设定pictureBox的大小和位置实现的。

if (common.isFullScreen == true)
            {
                this.picPlayWindow.Width = players1.Width - 2;
                this.picPlayWindow.Height = players1.Height - 2;

                this.picPlayWindow.Location = new Point(2, 2);
                this.picPlayWindow.Visible = true;
            }
            else
            {
                Size ds = ourVideo.DefaultSize;

                this.picPlayWindow.Width = players1.Width - 2;
                this.picPlayWindow.Height = players1.Width * ds.Height / ds.Width;

                int x = 2;
                int y = players1.Height / 2 - this.picPlayWindow.Height / 2;
                this.picPlayWindow.Location = new Point(x, y);
                this.picPlayWindow.Visible = true;
            }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值