
Introduction
- Windows Media Player object (COM Component).
- Shockwave flash object (COM Component)
- Create your Windows application.
- From the Tools Windows click Choose Items.
- Select the COM Components Tab.
- Search for "Windows Media Player" and click OK.

Now you can see the Windows Media Player will be added to your Tools windows. Just drag and drop the control to your Windows Forms.

My Audio/video Player has the following features:
-
Load audio/video File and add to playlist.
-
Play audio/video File
-
Pause audio/video File
-
Stop audio/video File
-
Play previous Song
-
Play Next Song
-
Play First Song of Play List
-
Play Last Song of Play List
- How to add Shockwave Flash Object COM Component to our Windows application
- Create your Windows application
- From the Tools Windows click Choose Items
- Select the COM Components Tab
- Search for "Shockwave Flash Object" and click OK


Note: To play the YouTube video in our Shockwave Flash Object the YouTube URL should be edited.
For example we have the YouTube URL https://www.youtube.com/watch?v=Ce_Ne5P02q0
To play this video we need to delete "watch?" from the URL and also we need to replace the "=" next to "v" as "/".
So here for example the actual URL should be edited to be like "http://www.youtube.com/v/Ce_Ne5P02q0" .
If we do not edit the URL as in the preceding then it will not play in Shockwave.
Audio/Video Player Code
- //Load Audio or Vedio files
- private void btnLoadFile_Click(object sender, EventArgs e)
- {
- Startindex = 0;
- playnext = false;
- OpenFileDialog opnFileDlg = new OpenFileDialog();
- opnFileDlg.Multiselect = true;
- opnFileDlg.Filter = "(mp3,wav,mp4,mov,wmv,mpg,avi,3gp,flv)|*.mp3;*.wav;*.mp4;*.3gp;*.avi;*.mov;*.flv;*.wmv;*.mpg|all files|*.*";
- if (opnFileDlg.ShowDialog() == DialogResult.OK)
- {
- FileName = opnFileDlg.SafeFileNames;
- FilePath = opnFileDlg.FileNames;
- for (int i = 0; i <= FileName.Length - 1; i++)
- {
- listBox1.Items.Add(FileName[i]);
- }
- Startindex = 0;
- playfile(0);
- }
- }
- #endregion
This method will be called from First, Next, Previous, Last and from the List Box Selected Index Change event with passing the “selectedindex” value. In this method from the array check for the selected file and play using the " WindowsMediaPlayer.URL" as in the following:
- // To Play the player
- public void playfile(int playlistindex)
- {
- if (listBox1.Items.Count <= 0)
- { return; }
- if (playlistindex < 0)
- {
- return;
- }
- WindowsMediaPlayer.settings.autoStart = true;
- WindowsMediaPlayer.URL = FilePath[playlistindex];
- WindowsMediaPlayer.Ctlcontrols.next();
- WindowsMediaPlayer.Ctlcontrols.play();
- }
- #endregion
- #region This is Windows Media Player Event which we can used to fidn the status of the player and do our actions.
- private void WindowsMediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
- {
- int statuschk = e.newState; // here the Status return the windows Media Player status where the 8 is the Song or Vedio is completed the playing .
- // Now here i check if the song is completed then i Increment to play the next song
- if (statuschk == 8)
- {
- statuschk = e.newState;
- if (Startindex == listBox1.Items.Count - 1)
- {
- Startindex = 0;
- }
- else if (Startindex >= 0 && Startindex < listBox1.Items.Count - 1)
- {
- Startindex = Startindex + 1;
- }
- playnext = true;
- }
- }
- #endregion
- WindowsMediaPlayer.Ctlcontrols.next();
- WindowsMediaPlayer.Ctlcontrols.play();
- WindowsMediaPlayer.Ctlcontrols.Stop();
Here in the button click I provide the input of the TextBox to the Shockwave Flash objectmovie property.
- private void btnYoutube_Click(object sender, EventArgs e)
- {
- ShockwaveFlash.Movie = txtUtube.Text.Trim();
- }
I have created the Audio and Video player as the User Control. In my project file you can find both “AudioVedioCntl.cs” and “YouTubeCntl.cs” inside the PlayerControls folder. Create the object for the user controls and add the controls to our form or Panel. In the form load I called a method “LoadPlayerControl”. To this method I passed the parameter as 0 and 1, 0 for adding and displaying the Audio Player to the panel and 1 for adding and displaying the YouTube player.
- private void frmMain_Load(object sender, EventArgs e)
- {
- LoadPlayerControl(0);
- }
- private void LoadPlayerControl(int playerType)
- {
- pnlMain.Controls.Clear();
- if (playerType == 0)
- {
- SHANUAudioVedioPlayListPlayer.PlayerControls.AudioVedioCntl objAudioVideo = new PlayerControls.AudioVedioCntl();
- pnlMain.Controls.Add(objAudioVideo);
- objAudioVideo.Dock = DockStyle.Fill;
- }
- else
- {
- PlayerControls.YouTubeCntl objYouTube = new PlayerControls.YouTubeCntl();
- pnlMain.Controls.Add(objYouTube);
- objYouTube.Dock = DockStyle.Fill;
- }
- }

mayur rankPosted Nov 2, 2015, 3:26 AM
good Work Syed Shanu, I have one problem In youtube player normally video streaming work fine but when video buffer it jump to foreword for ex. when video time 00:08 sec and it buffer it jump to 00:20 sec when it release it back to 00:09 sec, It has any solution to smooth video time showing...
sezayi yuksektepePosted Jun 8, 2015, 9:29 AM
Than you so much bro.
Gourav ShuklaPosted May 14, 2015, 11:43 AM
Good Lines Of code
Syed ShanuPosted Apr 8, 2015, 6:18 PM
Thank You Vithal
Vithal WadjePosted Apr 8, 2015, 2:55 PM
good work
Syed ShanuPosted Apr 6, 2015, 5:52 PM
Thank You Akhil
Akhil GargPosted Apr 6, 2015, 5:51 PM
nice article. .
Syed ShanuPosted Apr 6, 2015, 10:43 AM
ThankYou Santhakumar
Santhakumar MunuswamyPosted Apr 6, 2015, 10:40 AM
Good work
Syed ShanuPosted Apr 6, 2015, 10:04 AM
Thank you Gowtham.
Gowtham RajamanickamPosted Apr 6, 2015, 10:02 AM
once again you proved
Gowtham RajamanickamPosted Apr 6, 2015, 9:59 AM
good
Syed ShanuPosted Apr 6, 2015, 5:14 AM
Thank You Nitin Tyagi :)
NitinPosted Apr 6, 2015, 4:47 AM
good one