www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - problems playing audio with mciSendString

reply Tyro[a.c.edwards] <nospam home.com> writes:
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
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 );


when file exists:
0 - 0 - 0

when file does not exist:
275 - 263 - 263
Nov 02 2010
parent Tyro[a.c.edwards] <nospam home.com> writes:

The problem was that mciSendString was immediately returning control
to the caller after being called. This simple change fixed the

mciSendString("play myFile wait");
Nov 02 2010