Path: news.cs.au.dk!news.net.uni-c.dk!howland.erols.net!rill.news.pipex.net!pipex!server1.netnews.ja.net!pegasus.csx.cam.ac.uk!ljw1004 From: ljw1004@cus.cam.ac.uk (L.J. Wischik) Newsgroups: comp.lang.beta,comp.lang.pascal.delphi.components.misc,comp.lang.pascal.delphi.components.usage,comp.lang.pascal.delphi.components.writing,comp.lang.pascal.delphi.misc Subject: Re: AVI with sound Date: 29 Jan 1999 23:34:41 GMT Organization: University of Cambridge, England Lines: 94 Message-ID: <78tgih$j3b$1@pegasus.csx.cam.ac.uk> References: <36b23891.0@kaos.fastnet.co.uk> NNTP-Posting-Host: ursa.cus.cam.ac.uk Xref: news.cs.au.dk comp.lang.beta:11806 comp.lang.pascal.delphi.components.misc:17641 comp.lang.pascal.delphi.components.usage:13025 comp.lang.pascal.delphi.components.writing:15702 comp.lang.pascal.delphi.misc:182981 Alex Tame wrote: >Does anyine have a piece of code that will allow the extraction from >application EXE AVI files with sound that can then be played. >Something along the lines of TAnimate but with the facility to play the >sound. >"LOADFROMRESOURCE" would be ideal but have not been able to find any >references to AVI files. If someone has a component ready-made that would be good. Otherwise, you could look at and adapt the following code I wrote in a BCB3 program, which plays an AVI from resource memory. It sometimes caused crashes if two separate applications tried to play the AVI from the same memory block: you should therefore protect it with a system mutex or some such. //--------------------------------------------------------------------------- // Here are a couple of global variables for the multimedia playback, // so it can play from a memory AVI char *lpData=NULL; long fileSize=0; bool alreadyOpened=false; LRESULT CALLBACK IOProc(LPMMIOINFO lpMMIOInfo,UINT uMessage,LPARAM lParam1,LPARAM lParam2); //--------------------------------------------------------------------------- __fastcall TSaverForm::TSaverForm(TComponent* Owner) : TScrForm(Owner) { Purpose=smSaver; HaveStarted=false; } __fastcall TSaverForm::~TSaverForm() { if (HaveStarted) { MediaPlayer->Close(); mmioInstallIOProc(mmioFOURCC('M','E','Y',' '), NULL,MMIO_REMOVEPROC); // Don't need to free the resource } } //--------------------------------------------------------------------------- void __fastcall TSaverForm::FormShow(TObject *Sender) { if (HaveStarted) return; HRSRC hres=FindResource(HInstance,"MYAVI",RT_RCDATA); HGLOBAL hGlob=LoadResource(HInstance,hres); lpData=(char *)LockResource(hGlob); mmioInstallIOProc(mmioFOURCC('M','E','Y',' '), (LPMMIOPROC)IOProc, MMIO_INSTALLPROC | MMIO_GLOBALPROC); MediaPlayer->Display=this; MediaPlayer->Open(); //int w=320,h=200; //TRect rc; rc.Left=(Width-w)/2; rc.Top=(Height-h)/2; //rc.Right=rc.Left+w; rc.Bottom=rc.Top+h; MediaPlayer->DisplayRect=Rect(0,0,Width,Height); MediaPlayer->Notify=true; MediaPlayer->Wait=false; MediaPlayer->Play(); HaveStarted=true; } //--------------------------------------------------------------------------- void __fastcall TSaverForm::MediaPlayerNotify(TObject *Sender) { MediaPlayer->Notify=true; MediaPlayer->Wait=false; MediaPlayer->Play(); } //--------------------------------------------------------------------------- LRESULT CALLBACK IOProc(LPMMIOINFO lpMMIOInfo, UINT uMessage, LPARAM lParam1, LPARAM lParam2) { 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 0: lpMMIOInfo->lDiskOffset = lParam1; break; case 1: lpMMIOInfo->lDiskOffset += lParam1; break; case 2: 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 } } -- Lucian Wischik, Queens' College, Cambridge CB3 9ET. www.wischik.com/lu