Axwindowsmediaplayer没有以编程方式在Winforms中显示视频C# [英] Axwindowsmediaplayer not displaying the video in winforms programmatically C#

查看:86
本文介绍了Axwindowsmediaplayer没有以编程方式在Winforms中显示视频C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我有一个Windows应用程序,我想播放音频/视频文件。



首先,我在项目解决方案的Com选项卡中添加了对WindowsMediaPlay的引用。然后我通过右键单击菜单工具并选择WindowsMediaPlayer将其添加为工具。



我尝试过:



我试过这段代码来运行音频/视频文件。

Dear All,

I have one windows application where I want to play audio/videos files.

First of all, I have added the reference to the WindowsMediaPlay in Com tab in my project solution. I have then added this as the tool by right-clicking in the menu tool and selected the WindowsMediaPlayer.

What I have tried:

I have tried this code to run audio/videos files.

using AxWMPLib;

//method
if (QuestionContext.Image != null)
            {
                string fileExtension = Path.GetExtension(QuestionContext.Image.TempLocalPath);
                List<string> imageFileExtensions = new List<string>() { ".png", ".jpg", ".jpeg", ".bmp", ".gif" };
                List<string> audioFileExtensions = new List<string>() { ".mp3", ".ogg", ".wav", ".wma" };
                List<string> vedioFileExtensions = new List<string>() { ".mp4", ".wmv", ".mpeg", ".avi", ".mp3", ".ogg", ".wav", ".wma" };

                if (imageFileExtensions.Contains(fileExtension))
                {
                    PictureBox pictureBoxQuestionImage = new PictureBox();
                    pictureBoxQuestionImage.SizeMode = PictureBoxSizeMode.Zoom;
                    pictureBoxQuestionImage.Dock = DockStyle.Fill;
                    pictureBoxQuestionImage.Load(QuestionContext.Image.TempLocalPath);

                    PanelMedia.Controls.Add(pictureBoxQuestionImage);
                }
                else if (vedioFileExtensions.Contains(fileExtension))
                {
                    AxWindowsMediaPlayer mediaPlayer = new AxWindowsMediaPlayer();
                    ((System.ComponentModel.ISupportInitialize)(mediaPlayer)).BeginInit();
                    mediaPlayer.CreateControl();


                    mediaPlayer.enableContextMenu = true;
                    mediaPlayer.Name = "mediaPlayer";
                    mediaPlayer.Enabled = true;
                    mediaPlayer.URL = QuestionContext.Image.TempLocalPath;
                    mediaPlayer.settings.setMode("loop", true);
                    PanelMedia.Controls.Add(mediaPlayer);
                    mediaPlayer.Dock = DockStyle.Fill;
                    ((System.ComponentModel.ISupportInitialize)(mediaPlayer)).EndInit();

                    mediaPlayer.uiMode = "full";
                    mediaPlayer.Ctlcontrols.play();
                }





点击此处查看我的代码输出



当我跑步时我的应用程序,WindowsMediaPlayer只运行音频而不显示视频,即使该文件是视频文件。



任何人都可以帮我解决这个问题。





谢谢



Click here to see the output of my code

When I run my application, the WindowsMediaPlayer running only audio and not displaying the video, even though the file is a video file.

Can anyone please help me to resolve this.


Thanks

推荐答案

您尚未证明该文件没有损坏。或者窗口不是太小。为什么不首先使用工作样本(使用那个文件)?



没有快速回答,因为你没有做一些快速测试。



在Windows解决方案中嵌入Windows Media Player控件 - Windows应用程序Microsoft Docs [ ^ ]
You haven't proved that the file is not corrupt. Or the "window" is not "too small". Why don't you get a "working sample" working first (with "that" file)?

There is no "quick answer" because you did not do some "quick testing".

Embedding the Windows Media Player Control in a C Solution - Windows applications | Microsoft Docs[^]


这篇关于Axwindowsmediaplayer没有以编程方式在Winforms中显示视频C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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