Using Windows Media Player Class
Playing a DVD, and Opening a
picture file, and so on
With an object of Windows Media Player class, you can open various picture or audio files, and also can play a DVD. To develop an application, which uses Windows Media Player class, first create a new form application (Figure 1).
Figure 1
How to create a new form application is explained at this website.
To add the Windows Media Player item to Toolbox, click on the pane of Toolbox with the right button of the mouse (Figure 2).
Figure 2
Select the gChoose Itemsch menu item. The Choose Toolbox Items dialog window will be shown (Figure 3). Mark the Windows Media Player item on COM Component page, then click the OK button (Figure 3).
Figure 3
Now, the Windows Media Player item is listed in Toolbox (Figure 4).
Figure 4
Put items on the form as shown in Figure 5.
Figure 5
How to copy items from Toolbox on the form is explained at the website
http://mcn-www.jwu.ac.jp/~yokamoto/openwww/vsg/VCpp2012FormApp/GUIComponents/
Write the following codes. How to prepare event handler functions is also explained at the above website, i.e.
http://mcn-www.jwu.ac.jp/~yokamoto/openwww/vsg/VCpp2012FormApp/GUIComponents/
==================================================================================
#pragma
once
#include
<stdlib.h> // For system() function
namespace MP_Sample {
.
.
.
#pragma
endregion
private: System::Void buttonClose_Click(System::Object^ sender, System::EventArgs^ e) {
if (system("taskkill /IM
vmplayer.exe") != 0)
system("C:\\Windows\\System32\\taskkill.exe /IM
wmplayer.exe");
this->Close();
}
private: System::Void buttonOpen_Click(System::Object^ sender, System::EventArgs^ e) {
openFileDialog1->ShowDialog();
axWindowsMediaPlayer1->openPlayer(openFileDialog1->FileName);
}
private:
System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
axWindowsMediaPlayer1->Hide();
}
};
}
==================================================================================
Build and run the project. A form will appear (Figure 6).
Figure 6
Click the Open button, then the Open dialog window will be displayed (Figure 7).
Figure 7
Choose the file to open and click the Open button. In the case of Figure 7, DVD will be played.
The files of the project are compressed as MP_Sample.zip. This file can be downloaded by clicking the name MP_Sample.zip. The project files extracted from the downloaded file can be opened by Visual Studio 2015.