Help and Support
 

powered byLive Search

How To Use MCI to Play AVI/WAVE Files from Memory

Article ID:155360
Last Review:July 11, 2005
Revision:1.2
This article was previously published under Q155360

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
				

APPLIES TO
Microsoft Platform Software Development Kit-January 2000 Edition

Back to the top

Keywords: 
kbhowto KB155360

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.