• Welcome to Valhalla Legends Archive.
 

Undefined function?

Started by Eli_1, April 12, 2004, 02:46 PM

Previous topic - Next topic

Eli_1

I'm just trying to port a VB example on playing an mp3 to C++, but when I try to compile it can't find the mciExecute function.

Info on mciExecute:
msdn.microsoft.com/library/en-us/multimed/ htm/_win32_mciexecute.asp

Here's the code I'm using:

#include <windows.h>
#include <Mmsystem.h>
#include <winuser.h>
#include <stdio.h>
#include <string.h>

int main() {
char *command = new char[512];

   strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
   mciExecute(command);
   strcpy(command, "PLAY mp3test WAIT");
   mciExecute(command);
   strcpy(command, "CLOSE mp3test");
   mciExecute(command);

   delete command;
   return 0;
}


Any help would be appreciated  :-\

Eibro

strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
You need to use / for directories, or a double backslash (\\). A single backslash is interpreted as an escape sequence by the compiler.
Eibro of Yeti Lovers.

Eli_1

Quote from: Eibro on April 12, 2004, 03:04 PM
strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
You need to use / for directories, or a double backslash (\\). A single backslash is interpreted as an escape sequence by the compiler.
Oh yea, I keep forgetting about that. Thanks, Eibro. I still don't know why it isn't finding that function though.

K

The page you linked to was a 404 for me, but I assume the problem is that you need to link against Winmm.lib.

Eli_1

#4
Ok, I did some more searching on google, and I couldn't find a single example in C++ that used mciExecute. But I did see tons of examples using mciSendString, so that's what I ended up using, and it works flawlessly now.

Another problem I was having is trying to use an incorrect MCI device for playing mp3's. I found out I actually need to use MPEGVideo and not cdaudio like I was trying to use in my first post.

Stated in Win.ini:
Quote
[mci extensions]
...
wav=waveaudio
avi=AVIVideo
mp3=MPEGVideo
...

Here's the new working code:

/* Main.cpp
* This will the song 'Soil - Redefine' :-O
*/
#include <windows.h>
#include <mmsystem.h>
#include <winuser.h> // <-- I don't think this is needed
#include <stdio.h>
#include <string.h>

int main() {
char *command = new char[512];
int i;
   /* I found out that the main reason I was failing
    * was that I was using the wrong type of device to
    * to play files with an mp3 extension.
    * I later noticed that I need to use 'MPEGVideo' and 'MPEGVideo2'
    * for almost everything, as stated in WIN.ini
    */
   
   /* Open my file */
   strcpy(command, "open c:\\soil.mp3 type MPEGVideo alias mp3test wait");
   i = mciSendString(command, NULL, 0, 0);
   if (i != 0) {
      char buffer[128];
      mciGetErrorString(i, buffer, 128);
      printf("Error in 'open': %s\n", buffer);
   }
   
   /* Play the file. */
   strcpy(command, "play mp3test wait");
   i = mciSendString(command, NULL, 0, 0);
   if (i != 0) {
      char buffer[128];
      mciGetErrorString(i, buffer, 128);
      printf("Error in 'play': %s\n", buffer);
   }
   
   /*
    * Sending "all" in the with the 'close' command will
    * close all devices opened by this app.
    */

   strcpy(command, "close all wait");
   mciSendString(command, NULL, 0, 0);
   delete command; // !! :D
   return 0;
}