Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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();
                }


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
Posted
Updated 20-Feb-19 4:38am
v3

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900