Re: Playing an MP3 file using WaveOut functions
- From: Punit Kaur <PunitKaur@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 13:44:02 -0700
Thanks a lot. I used the MCI Driver option and it works well. The sound does
not cut of like in PlaySound function. Now I have another problem. I am
implementing a play thread that continuously plays all the mp3 files
appearing in my application's list control. So I have something like the
following:
for (int j=0; j<SF_Count;j++)
{
//some code
if(m_Audio !=NULL)
{
MCIWndDestroy(m_Audio);
}
m_Audio= NULL;
if(m_Audio == NULL)
{
m_Audio = MCIWndCreate(NULL,NULL,NULL,SaveFiles[j].PlayFilePath_Sel);
ShowWindow(m_Audio, SW_HIDE);
}
else
{
MCIWndHome(m_Audio);
}
MCIWndPlay(m_Audio);
}
The above code creates a MCIWnd everytime it plays a new mp3 file. I do not
want that MCIWnd window to appear so I have added code to hide it. But
creating a MCIWnd and then hiding it for every file is causing the
application and screen to flicker. Could you suggest how I could avoid this?
Also I would like to embed this control into my Dialog based application
instead of having it as a separate window. How can I achieve this?
Thanks
"Alessandro Angeli [MVP::DS/MF]" wrote:
Punit Kaur wrote:.
Can someone explain me the steps to write a program that
would take an mp3 file as input and play it using Waveout
functions. I nkow that Waveout function plays from a
buffer. How do I convert the mp3 files to the
appropriately formatted buffer that waveout functions can
understand and play the audio?
I tried using the PlaySound function directly on the mp3
files but it is giving problems by cutting off the last
few seconds of the audio file. Hence I decided to shift
to Waveout option.
You need to decompress the MP3 stream to PCM before passing
the PCM buffers to waveOut. One way to do that is to use the
acmStream functions with the system's MP3 codec. Since an
MP3 file is a raw MP3 stream, you can just read the file
without any parsing and pass the blocks directly to
acmStreamConvert().
However, since you need to properly configure the ACM
decoder using an MPEGLAYER3WAVEFORMAT structure, you either
must know in advance the exact format of the MP3 file or you
need to parse the MP3 frame header to gather the values to
fill in the structure.
If your MP3 files contain ID3 tags, you should also skip the
tags, especially if they are ID3v2 tags that contains large
blocks of data, like JPEG images.
You can find instructions on all of this in my FAQ (see my
signature below). You can read about ID3 on
http://en.wikipedia.org/wiki/ID3.
If you want something that does all of the above for you,
you can use the WMSyncReader or WMReader objects documented
in the WindowsMediaFormat SDK. The WM reader objects are
supposed to only read ASF files, but they also support MP3
ones and will parse, skip and decode the MP3 for you.
If you want something that does all of the above and also
actually plays the audio, you can use DirectShow. The
default audio rendering filter in DirectShow is DirectSound,
but you can manually choose the other system's filter based
on waveOut.
The MPEGVideo MCI driver will also play MP3 files for you
(in fact, it is an MCI wrapper for DirectShow).
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
// http://www.riseoftheants.com/mmx/faq.htm
- References:
- Re: Playing an MP3 file using WaveOut functions
- From: Alessandro Angeli [MVP::DS/MF]
- Re: Playing an MP3 file using WaveOut functions
- Prev by Date: Re: Playing an MP3 file using WaveOut functions
- Next by Date: Re: Callback - I need a little explaination...
- Previous by thread: Re: Playing an MP3 file using WaveOut functions
- Next by thread: Re: Trouble with asf reader output pin configuration
- Index(es):
Relevant Pages
|