Making Media Player under VC2005

Source: Internet
Author: User
Tags resource

A few days ago suddenly a whim, intend to use VC to do a media player, so to the Internet search, found that a lot of good people posted a lot of examples (very grateful), some are VC6 wrote, some are vc2003/2005 written, are directly through the Wmp.dll (WINDOW The active control with MEDIA PLAYER9, stored in the C:\WINDOWS\system32 directory. I have a bit of rejection of VC6 (haha, is to think that its C + + standard support is too bad, so the general do not consider when the project, really no way to use when), directly began to follow the prompts in the VC2005 prepared.

The beginning is always the same:

1, add a solution;

2, under the solution to add an MFC dialog box program;

3, edit the dialog box resources, on the left toolbar by selecting the item-"COM component, select Windows Media Player to add, after adding a toolbar that is a Windows Media Player item, pull it into the design window, select its properties, Set Enablecontextmenu to True, that is, allow the Player pop-up menu;

4, to the dialog box to add a menu, menu function is very simple, is the file-"open/exit;"

In the Resource window, select Add a menu by right-clicking, default to Idr_menu1, and then in the properties of the dialog box to set the menu to Idr_menu1, then in the dialog box to include the menus:

5, the implementation of submenu items to open the function:

In the Open submenu of the Resource window, right-click, select Add Event processing, message Select command, class list select Dlg, then edit function:

void CMPlayDlg::On32771()
{
CFileDialog dlg(TRUE, NULL, L"*.*", OFN_FILEMUSTEXIST,
L"Active Streaming Format(*.asf)|*.asf|"\
L"Audio Video Interleave Format(*.avi)|*.avi|"\
L"RealAudio/RealVideo(*.rm)|*.rm|"\
L"Wave Audio(*.wav)|*.wav|"\
L"MIDI File(*.mid)|*.mid|"\
L"所有文件(*.*)|*.*||");
if (dlg.DoModal() == IDOK) {
//m_ctrlMPlayer.put_stretchToFit(TRUE); // 伸缩画面,使其适合播放窗口
// …… 可以在此进行各种其他设置
m_ctrlMPlayer.put_URL(dlg.GetPathName()); // 传递媒体文件到播放器
}
}

6, the realization of the window Wmsize:

Because the window size will be changed, so the video window in the window to make the corresponding changes, it is necessary to implement the window Wm_size function:

void CMPlayDlg::OnSize(UINT nType, int cx, int cy)
{
 CDialog::OnSize(nType, cx, cy);
 if (m_ctrlMPlayer)
 {
  m_ctrlMPlayer.MoveWindow(0, 0, cx-40, cy);
 }
}

Note: Debug always error before adding if (M_ctrlmplayer), release is OK, then I think it should be the program to start, M_ctrlmplayer has not initialized, so the error.

Such a simple player is made.

Since I want to see the name of the currently playing media and want to see the progress, I need to introduce Cwmpmedia and Cwmpcontrols control objects, so in the solution's Explorer right-add Class-"mfc-" MFC classes in ActiveX-" Select Windows Media player<1.0> in the Drop-down list, and then select some of the related classes on the left to pull to the right, OK, at this point the corresponding H and CPP files are added in;

I want to control the playback of the player, refer to some of the online code, so:

m_control =  m_ctrlMPlayer.get_controls();
 double d = m_control.get_currentPosition();
 d = d+1;
 CWMPMedia m_media = static_cast<CWMPMedia>(m_ctrlMPlayer.get_currentMedia());
 CString s = m_media.get_name();

Haha, always compile does not pass, later checked, found Cwmpcontrols is inherited from CWnd, so copied from the Internet cwmpcontrols inherit from COleDispatchDriver H and CPP code. Compilation passed (it took a lot of time to find out about this problem).

Haha, jiehuaxianfo, hope to have encountered the same problem friends less take a detour.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.