HOWTO: Use MCI to Play AVI/WAVE Files from Memory

Last reviewed: January 23, 1998
Article ID: Q155360

The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)

SUMMARY

MCI (Media Control Interface) provides a high-level interface to play multimedia files (or "device elements" as defined in MCI). By default, MCI WAVE/AVI drivers (MCIAVI and MCIWAVE) use mmioOpen to open a file. If the file name contains a "+" character, mmioOpen will look for a custom procedure as identified by the three-character file extension to handle the reading and writing of a file. This technique can be applied to allow MCI to play WAVE/AVI files that are already loaded into memory.

The following steps demonstrate this approach. We use "MEY" as the file extension in this example:

  1. Install a custom MMIO procedure as follows:

          mmioInstallIOProc(mmioFOURCC('M', 'E', 'Y', ' '), (LPMMIOPROC)IOProc,
    
                MMIO_INSTALLPROC | MMIO_GLOBALPROC);
    
       Note that IOProc is the name of the custom procedure.
    
    

  2. Use the MCI open command except to add a plus sign (+) at the end of a file name. For instance,

          open test.MEY+ type waveaudio (or avivideo) alias test
    

    Because there is a "+" character in the file name, mmioOpen will not open any files. Instead, the custom mmio procedure is identified. Subsequently, all the I/O messages are routed to that procedure.

  3. Then, we can use usual MCI command. For instance:

          play test
          close test
    

  4. When done with this custom mmio procedure, we should remove it by

          mmioInstallIOProc(mmioFOURCC('M', 'E', 'Y', ' '), NULL,
          MMIO_REMOVEPROC);
    

MORE INFORMATION

The following is sample code for the custom mmio procedure IOProc. Here you assume that the WAVE/AVI file has been loaded into memory and pointed to by lpData. Also the variable fileSize records the file length in bytes:

   static char * lpData;
   static long fileSize;
   LRESULT CALLBACK IOProc(LPMMIOINFO lpMMIOInfo, UINT uMessage, LPARAM
   lParam1, LPARAM lParam2)
   {
      static BOOL alreadyOpened = FALSE;

      switch (uMessage) {
         case MMIOM_OPEN:
            if (alreadyOpened)
               return 0;
       alreadyOpened = TRUE;
   
       lpMMIOInfo->lDiskOffset = 0;
       return 0;
   
         case MMIOM_CLOSE:
            return 0;
   
         case MMIOM_READ:
       memcpy((void *)lParam1, lpData+lpMMIOInfo->lDiskOffset,
   lParam2);
            lpMMIOInfo->lDiskOffset += lParam2;
   
            return (lParam2);
   
         case MMIOM_SEEK:
            switch (lParam2) {
               case SEEK_SET:
                  lpMMIOInfo->lDiskOffset = lParam1;
                  break;
   
               case SEEK_CUR:
                  lpMMIOInfo->lDiskOffset += lParam1;
   
               case SEEK_END:
                  lpMMIOInfo->lDiskOffset = fileSize - 1 - lParam1;
                  break;
            }
            return lpMMIOInfo->lDiskOffset;
   
         default:
           return -1; // Unexpected msgs.  For instance, we do not
                                // process MMIOM_WRITE in this sample
     }// end of switch
   }//end of IOProc


Additional query words: audio video playback
Version : 4.0, 3.51
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 23, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.