( Index )
Month

Brief Information about the December 2005 CSIG Meeting

DropMp3.exe - A Music Player for Mp3 and Wma Files

by Bruce Arnold

3rd Tuesday of the month. 7:30PM - C/C++ Group, SPRS

DropMp3 Application

Welcome to the C++ Users Group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.

OBJECT ...

The object of this application is to play MP3 or WMA files from a Drag and Drop List. Use "Drag and Drop" from Windows Explorer to play any file or group of files. Use "Drag and Drop" with folder names to play all of the files in the folder. The application uses the Microsoft "MCIWnd Window Class". Here are several paragraphs quoted from the Microsoft Help Screens:

MCIWnd Window Class

MCIWnd is a window class for controlling multimedia devices. A library of functions, messages, and macros associated with MCIWnd provides a simple method to add multimedia playback or recording capabilities to your applications.

About the MCIWnd Window Class

The MCIWnd Window class is easy to use. By using a single function, MCIWndCreate your application can create a control that plays any device that uses the media control interface (MCI). These devices include CD audio, waveform-audio, MIDI, and video devices.

Automating playback is also quick and easy. Using only one function and two macros, an application can create an MCIWnd window with the appropriate media device, play the device, and close both the device and the window when the content has finished playing.

Note Some devices play content that is stored in files. Other devices, such as CD audio devices, play content that is stored in another medium. For purposes of clarity, this overview refers to both circumstances as "playing the device."

C++ Language Elements

Microsoft Visual C++ Version 6.0.
Windows API.
Dialog Based Applications.
Timers.
MCI Windows Class
Controlling Volume
Simple Drag and Drop.
Shuffle Algorithm for List Box
ListBox handling.

At the meeting on Tuesday night we will be discussing the utility and the source code.


SAMPLE CODE
===========
/////////////////////////////////////////////////////////////////////////////
//  Scroll the file name.   Land here every 1/2 second or so.

#pragma warning( push )
#pragma warning( disable : 4100 )   // unreferenced formal parameter

void CDropDlg::OnTimer(UINT nIDEvent) 
    {
    static int idx=0, count=0;      static CString lastsong;
    static enum stateTAG { PAUSEINIT, PAUSE, SCROLLINIT, SCROLL } state = PAUSEINIT;

    if (m_Playing == 0)
        {
        state = PAUSEINIT;
        m_CurrentFileShort = DEFAULT_TITLE;
        }

    if (lastsong != m_CurrentFileShort)
        {
        state = PAUSEINIT;
        lastsong = m_CurrentFileShort;
        }
    if (idx >= m_CurrentFileShort.GetLength())
        state = PAUSEINIT;
    
    switch (state)
        {
        case PAUSEINIT:
                        idx = 0;
                        count = 0;
                        state = PAUSE;
                        break;
        case PAUSE:
                        if (++count > 5) state = SCROLLINIT;
                        break;
        case SCROLLINIT:
                        idx = 0;
                        state = SCROLL;
                        break;
        case SCROLL:
                        if (++idx >= m_CurrentFileShort.GetLength()) state = PAUSEINIT;
                        break;
        }
    SetWindowText(m_CurrentFileShort.Mid(idx));
    }

#pragma warning( pop )

/////////////////////////////////////////////////////////////////////////////
//  Shuffle the songs in the list box.  (Button Hit)

#define REPLACE_STRING(IDX, STR) m_Files.DeleteString(IDX), m_Files.InsertString((IDX), (STR))

void CDropDlg::DoShuffle()                                  // With a name group that decreases 
    {                                                       // in size down to nothing, replace
    CString sLastFile, sRandFile;   int i, idxRand;         // the last name with a random name.

    srand( (unsigned)time( NULL ) );    // "Seed" the random number generator.

    for (i=m_Files.GetCount()-1; i>1; i--)
        {
        idxRand = rand() % i;
        m_Files.GetText(i,       sLastFile);    // get last value
        m_Files.GetText(idxRand, sRandFile);    // get a random value

        REPLACE_STRING( i,       sRandFile);
        REPLACE_STRING( idxRand, sLastFile);    // swap values
        }
    m_Index = -1;                               // anticipate next bump.
    if (m_Playing)                              // jump to the current song.
        m_Index = m_Files.SelectString(0, m_CurrentFile);
    }


Other Items - Program from Friday's Language Shootout

Available from download page.

Balls C++ Class Demo


"Random Access" questions start at 7:30 Tuesday night. See you there.
December 2005  C/C++ Meeting Random Access Notes
=================================================
www.acgnj.org         C Users Journal - www.cuj.com
www.codeproject.com          Dr Dobbs = www.ddj.com
www.codeguru.com
msdn.microsoft.com
www.dslreports.com

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page