A player made with a RealPlayer control

Source: Internet
Author: User

This article describes how to insert a Realplay control to enable playback of a media file, and the code runs as shown below:

The following is a brief introduction to the implementation steps:

First, the establishment based on the dialog box program

Add ActiveX controls RealPlayer G2 Control to the dialog box

(Engineering-> Add Engineering->compontent and controls->registed ActiveX controls).

Third, in the dialog box to add the source program shown in the button and static text to control the playback, such as control and display the song information its ID number, such as the source program

Iv. use MFC to map each button message

void Csunapplerealplayerdlg::onopen ()
{
Char szfilefilter[]=
"RM File (*.rm) |*.rm|"
"Mp3 File (*.mp3) |*.mp3|"
"MPEG File (*.mpeg) |*.mpeg|"
"Media File (*.asf) |*.asf|"
"Video File (*.dat) |*.dat|"
"MPGA File (*.MPGA) |*.mpga|"
"Wave File (*.wav) |*.wav|"
"AVI File (*.avi) |*.avi|"
"Movie File (*.mov) |*.mov|"
"Mid File (*.mid;*,rmi) |*.mid;*.rmi|"
"Wma File (*.wma) |*.wma|"
"All File (*.*) |*.*| |";
CFileDialog Dlg (True,null,null,ofn_hidereadonly,szfilefilter);
if (dlg. DoModal () ==idok) {
CString Pathname=dlg. GetPathName ();
Pathname.makeupper ();
M_player->setsource (PathName);
M_player->doplay ();
Setdlgitemtext (Idc_static1,m_player->getauthor ());
Setdlgitemtext (Idc_static2,m_player->gettitle ());
Setdlgitemtext (Idc_copyright,m_player->getcopyright ());
Setdlgitemtext (Idc_source,m_player->getsource ());
}
}
void Csunapplerealplayerdlg::onplay ()
{
Setdlgitemtext (Idc_static1,m_player->getauthor ());
Setdlgitemtext (Idc_static2,m_player->gettitle ());
Setdlgitemtext (Idc_copyright,m_player->getcopyright ());
Setdlgitemtext (Idc_source,m_player->getsource ());
M_player->doplay ();
  
UpdateData (FALSE);
SetTimer (1,20,null);
}
void Csunapplerealplayerdlg::ontimer (UINT nidevent)
{
if (0&&isrepeat)
M_player->doplay ();
Cdialog::ontimer (nidevent);
}
void Csunapplerealplayerdlg::onclose ()
{
When adding this code, don't forget to add the first two lines at the beginning of the stdafx.h
AnimateWindow (GetSafeHwnd (), 1000,aw_hide| Aw_blend);
KillTimer (0);
////////////////////////////////////
Use DestroyWindow to close windows here
More Shedusiu Apricot teacher pointing
///////////////////////////////////
This->destroywindow ();
  
}
void Csunapplerealplayerdlg::onfullscreen ()
{
M_player->dopause ();
M_player->setfullscreen ();
M_player->doplay ();
}
void Csunapplerealplayerdlg::onmp3down ()
{
ShellExecute (null,_t ("open"), "Http://sunapple.51.net", null,null,true);
  
}
void Csunapplerealplayerdlg::onpause ()
{
M_player->dopause ();
}
void Csunapplerealplayerdlg::onstop ()
{
M_player->dostop ();
KillTimer (0);
}
void Csunapplerealplayerdlg::onrepeat ()
{
M_player->setloop (TRUE);
if (isrepeat) {
Isrepeat=false;
Setdlgitemtext (Idc_repeat, "cycle");
}
Else
{
Isrepeat=true;
Setdlgitemtext (Idc_repeat, "normal");
}
}
void Csunapplerealplayerdlg::onlower ()
{
Todo:add your control notification handler code here
Short Volume=m_player->getvolume ();
M_player->dopause ();
M_player->setvolume (volume-100);
M_player->doplay ();
}
void Csunapplerealplayerdlg::onupper ()
{
Todo:add your control notification handler code here
Short Volume=m_player->getvolume ();
M_player->dopause ();
M_player->setvolume (volume+100);
M_player->doplay ();
}
void Csunapplerealplayerdlg::onfloat ()
{
Todo:add your command handler code here
ShellExecute (null,_t ("open"), "Http://sunapple.51.net", null,null,true);
}
void Csunapplerealplayerdlg::onpetroleum ()
{
Todo:add your command handler code here
ShellExecute (null,_t ("open"), "http://www.hdpu.edu.cn", null,null,true);
}

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.