问题描述
亲爱的,
我有一个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
推荐答案
这篇关于Axwindowsmediaplayer没有以编程方式在Winforms中显示视频C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!