Code:
#include <windows.h>
#include <stdio.h>
#if defined(_MSC_VER)
# pragma comment(lib, "Winmm.lib")
#endif
/*
* Plays an MP3 or WMA file.
*/
BOOL PlaySong(LPCTSTR szFile)
{
TCHAR szCommandString[1000];
wsprintf(szCommandString, TEXT("open \"%s\" type mpegvideo alias MediaFile"), szFile);
/* By default mci functions will return immediately and the task will be carried out
* asynchronously. To have the function wait, place the word "wait" at the end of the
* command string. ie. "play MediaFile wait" */
if (ERROR_SUCCESS == mciSendString(szCommandString, NULL, 0, NULL) &&
ERROR_SUCCESS == mciSendString(TEXT("play MediaFile"), NULL, 0, NULL))
{
return TRUE;
}
return FALSE;
}
int main(void)
{
if (!PlaySong(TEXT("C:\\Path To\\Your Song.wma")))
{
printf("Failed to play song!");
}
getchar();
return 0;
}
To play it in Windows Media Player, you could use system or ShellExecute.