Three MP3 playback Methods

Source: Internet
Author: User

Three MP3 playback Methods
1. Use the Windows Media Player Control
First, insert the Windows Media Player control and drag it to the dialog box. And name the control m_wmpplayer.
Void cmusicdlg: onbutton1 ()
{
// Todo: add your control notification handler code here
Cstring filename;
Cfiledialog DLG (true );
If (DLG. domodal () = idok)
{
Filename = DLG. getpathname ();
M_wmpplayer.seturl (filename );
}
}

2. Use MCI
Include header file # include <VFW. h>, library file vfw32.lib
Hwnd m_audio;

M_audio = mciwndcreate (this-> getsafehwnd (), AfxGetInstanceHandle (), ws_child | ws_visible | mciwndf_nomenu, null );

Void cmusicdlg: onbutton2 ()
{
// Todo: add your control notification handler code here
Cstring filename;
Cfiledialog DLG (true );
If (DLG. domodal () = idok)
{
Filename = DLG. getpathname ();
Mciwndopen (m_audio, filename. getbuffer (0), 0 );
Filename. releasebuffer ();

Mciwndplay (m_audio );
}
}

3. Use DirectShow
DirectX needs to be installed
Include header file # include <dshow. h>, library file strmiids. Lib
Igraphbuilder * pgbuilder;
Imediacontrol * pmcontrol;
Imediaposition * pmpos;

coinitialize (null); // initialize com
// create each object
cocreateinstance (clsid_filtergraph, null, clsctx_inproc, iid_igraphbuilder, (void **) & pgbuilder);
pgbuilder-> QueryInterface (iid_imediacontrol, (void **) & pmcontrol);
pgbuilder-> QueryInterface (iid_imediaposition, (void **) & pmpos);

void cmusicdlg: onbutton3 ()
{< br> // todo: add your control notification handler code here
cstring filename;
cfiledialog DLG (true);
If (DLG. domodal () = idok)
{< br> filename = DLG. getpathname ();
wchar wstrsoundpath [max_path]; // stores the path in the unicode format
multibytetowidechar (cp_acp, 0, filename. getbuffer (0),-1, wstrsoundpath, max_path);
filename. releasebuffer ();

Pgbuilder-> renderfile (wstrsoundpath, null); // call the file
// Play MP3 files
Pmpos-> put_currentposition (0); // move to the file header
Pmcontrol-> Run (); // play
}
}

# Define safe_release (p) if (null! = P) {P-> release (); P = NULL ;}

bool cmusicdlg: destroywindow ()
{< br> // todo: add your specialized code here and/or call the base class
// release the object
safe_release (pmcontrol);
safe_release (pmpos );
safe_release (pgbuilder);
couninitialize (); // release com
return cdialog: destroywindow ();
}

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.