problems playing audio with mciSendString

Tyro Tyro
Tue Nov 2 01:26:07 PDT 2010


Hello all,

I would really appreciate some assistance on this. The intent is to
create a vocabulary/flashcard program with proper pronunciations.
Pronunciations are saved as individual mp3 files which I want to
play whenever a new term is displayed. My current attempt is simply
to get the the file (any mp3 file really) to play. All indication
form the two references I'm using (http://msdn.microsoft.com/en-
us/library/dd757161(v=VS.85).aspx and
http://www.apitalk.com/windows-Programming/Play-Mp3,-Wav,-Wmv,-Mpg,-
Avi-Etc-Files-In-Win32-Api-Program.html) say that this little script
is supposed to work. The error codes as reported by mciSendString
even suggest that it is working, however I'm not hearing any sound
at all.

suggestions anyone?

import std.stdio : writeln;
import std.string : cstring = toStringz;
import std.c.windows.windows;

pragma(lib, "winmm.lib" );

extern(Windows) {
	uint mciSendStringA(
		LPCTSTR lpszCommand,
		LPTSTR lpszReturnString,
		uint cchReturn,
		HANDLE hwndCallback);
}

uint mciSendString(string s)
{
	return mciSendStringA( cstring(s), cast(LPTSTR)null, 0,
cast(HANDLE)0 );
}

void main()
{
	auto exist = mciSendString("open CC_10_mins.mp3 type
mpegvideo alias myFile");

	auto succeeded = mciSendString("play myFile");

	auto closed = mciSendString("close myFile");

	writeln( exist, " - ", succeeded, " - ", closed );
}


PROGRAM OUTPUT
==============

when file exists:
D:\code>play
0 - 0 - 0

when file does not exist:
D:\code>play
275 - 263 - 263


More information about the Digitalmars-d-learn mailing list