HOWTO: Use MCI to Play AVI/WAVE Files from Memory
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:
- 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.
- 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.
- Then, we can use usual MCI command. For instance:
play test
close test
- 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
Keywords :
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto
|