Mp3 play - MCI

This is a discussion on Mp3 play - MCI within the Windows Programming forums, part of the Platform Specific Boards category; Greetings! I tried to play an mp3 using MCI function, play(). But Visual C++ 6.0 doesn’t recognize the function. Below ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362

    Mp3 play - MCI

    Greetings!

    I tried to play an mp3 using MCI function, play(). But Visual C++ 6.0 doesn’t recognize the function. Below is what I have written.
    Code:
    #define _WIN32_WINNT 0x0501 
    #define WINVER 0x0501
    #include "stdafx.h"
    
    DWORD Play(LPSTR lpstrAlias) 
    { 
        char    achCommandBuff[128]; 
        wsprintf(achCommandBuff, "play ", lpstrAlias); 
        return mciSendString(achCommandBuff, NULL, 0, NULL); 
    } 
    
    int main(int argc, char* argv[])
    {	
    	Play("C:\\Program Files\\Britannica\\2002\\multimedia\\mp3\\oharp00004u2.mp3");
    	return 0;
    }
    What are the means of fixing this problem?
    Thanks.
    -geek@02

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    #include <windows.h> and link with winmm.lib. See mciSendString for details. In general, the required header and library are listed at the bottom of the relevant msdn page for each api function.

    Although that should enable you to compile and link your code it probably won't run as expected; this article discusses (console example, too) how to properly format the mci string (the lpstrAlias in your 'Play' function) to enable mp3 file playing.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    Sorry to bother you again.
    What must I do to link a library?

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Add any library names in the linker option of your project settings for msvc6.

    A quick and dirty way if using, in particular, ms compilers is to use a #pragma, for example:
    Code:
    #pragma comment(lib, "winmm.lib")
    but I wouldn't advise making a habit of that as it's not supported by many compilers.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    OK. Thanks a lot for the artical and the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. play MP3 on win32 consol project
    By Skull in forum C++ Programming
    Replies: 11
    Last Post: 02-09-2008, 03:30 PM
  2. not able to play MP3 files in SUSE 10.0
    By kris.c in forum Tech Board
    Replies: 0
    Last Post: 09-14-2006, 04:36 AM
  3. Gui Class With Tic Tac Toe
    By xxYukoxx in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2003, 04:28 PM
  4. Play Mp3...
    By Jperensky in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2003, 02:08 PM
  5. How do I play an MP3?
    By Hunter2 in forum Windows Programming
    Replies: 28
    Last Post: 05-20-2002, 08:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21