problems playing audio with mciSendString

Jimmy Cao jcao219 at gmail.com
Tue Nov 2 17:52:55 PDT 2010


I see a lot of á's which take the place of spaces.

On Tue, Nov 2, 2010 at 6:57 PM, Tyro[a.c.edwards] <nospam at home.com> wrote:

> 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
>
>
This code works for me:

import std.stdio;
import std.string;
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( toStringz(s), null, 0, cast(HANDLE)0);
}

void main()
{
    mciSendString("open erm.mp3 type mpegvideo alias myFile");

    mciSendString("play myFile");
    char* data;
    while(true)
    {
        mciSendStringA(toStringz("status myFile mode"), data, 128,
cast(HANDLE)0);
        auto result = std.conv.to!string(data);
        if(result == "playing")
            Sleep(1000);
    }

    mciSendString("close myFile");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101102/1fb6e233/attachment-0001.html>


More information about the Digitalmars-d mailing list