CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    9

    Problem on playing MIDI using MCI

    hi,
    I'm trying to use MCI to play a MIDI sequence, but the problem is that I can't hear anything after the device is successfully opened. Here's my code:

    Code:
    #include<windows.h>
    #include<stdio.h>
    #include<mmsystem.h>
    
    #pragma comment(lib,"winmm.lib")
    
    int main()
    {
        int i = 0;
    
        MCI_OPEN_PARMS mciOpen;
        mciOpen.lpstrDeviceType = L"mpegvideo";
        mciOpen.lpstrElementName = L"F:\\Program Files\\RPG Maker XP\\RGSS\\Standard\\Audio\\BGM\\011-LastBoss03.mid";    
        mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mciOpen);
    
        MCI_STATUS_PARMS mciStatusParms;
        mciStatusParms.dwItem = MCI_STATUS_LENGTH;
        mciSendCommand(mciOpen.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&mciStatusParms);   
        int curLength = mciStatusParms.dwReturn;
        printf("total length:%d\n", curLength);
    
        MCI_PLAY_PARMS mciPlay;
        mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);
        while(1)
        {
            printf("now playing\t%d\tseconds\r", i);
            i++;
            Sleep(1000);
        }
        return 0;
    }
    The program opened the device and obtained the media length (correctly), then the MCI_PLAY command is also sent and mciSendCommand returns. Then the program enters the while loop and starts to count in second, but I can't hear anything O.O...
    I've tried to change the device type to "sequencer", it still doesn't work..
    Then I tried to used mciSendString to play it, still..
    I've also tried to play media that are in WAV and MP3 format, and they both worked, so I don't know why MIDI doesn't, since it works fine using Microsoft media player.
    Any help is appreciated!

  2. #2
    Join Date
    May 2002
    Posts
    1,435

    Re: Problem on playing MIDI using MCI

    I would probably start by checking the return values of the MCI functions, but that's just me...

    General MCI Errors

  3. #3
    Join Date
    Mar 2009
    Posts
    9

    Re: Problem on playing MIDI using MCI

    Actually it returned 0, which means that there is no error... but thanks anyway.

  4. #4
    Join Date
    Apr 2004
    Posts
    102

    Re: Problem on playing MIDI using MCI

    Are you sure you do NOT have anything muted? You can check by right clicking on the speaker on task bar and checking the volume control. Be sure that mute is NOT checked for anything.

  5. #5
    Join Date
    May 2002
    Posts
    1,435

    Re: Problem on playing MIDI using MCI

    Quote Originally Posted by Helstorm View Post
    Actually it returned 0, which means that there is no error... but thanks anyway.
    OK, I am not an expert at MCI but based on the MSDN documentation your code raise a few issues that I would be concerned about.

    You call mciSendCommand() with the MCI_NOTIFY flag set but you pass it an uninitialized MCI_PLAY_PARMS structure - that doesn't look right at all to me. I would assume that you would need to specify the window (which possibly could be NULL for console app) plus the start and end positions.

    Also you mention that you check 'it' (the return value) but 'it' implies one function to me - not ALL of the MCI commands. Are you checking the return values of ALL of the MCI commands?

    And as for your MCI_OPEN_PARMS structure, you are not specifying all of the fields so you may be again passing uninitialized (random) data to the function. At the very least, you should be doing this with ALL of your structures:

    Code:
    MCI_OPEN_PARMS mciOpen;
    ::ZeroMemory(&mciOpen, sizeof(mciOpen));
    ... now set fields that you want to use

  6. #6
    Join Date
    Mar 2009
    Posts
    9

    Re: Problem on playing MIDI using MCI

    Quote Originally Posted by BobS0327 View Post
    Are you sure you do NOT have anything muted? You can check by right clicking on the speaker on task bar and checking the volume control. Be sure that mute is NOT checked for anything.
    Wow, you just solved my problem >_<
    In the volume control, my volume for SW Synth was all the way down, this is why I can't hear the music. I found that Windows Media Player automatically adjusts the volume to the midpoint of the scroll bar when playing MIDI, and sets it to 0 when the program exits whether I raise the volume from 0 or not. This is weird.
    Thank you very much
    And thanks to 0xC0000005 too, very nice advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured