Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

inserting avi clip in data field

Posted on 1998-03-05
3
322 Views
Last Modified: 2010-04-06
how to insert an avi clip in a data field table (delphi)?
please i want code.
0
Comment
Question by:t_medhat
  • 3
3 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1360100
Hi t_medhat,

I found this ones on the net, hope it sutes your needs :

AVI files can be sotored in BLOB (binary large object) fields. The
                             easist way to play an AVI file stored in a BLOB is to write the BLOB
                             data to a temporary file, then use the mulimedia player play the
                             file. The following example demonstrates how to store an AVI file
                             to a BLOB field, and also play the AVI file from the blob field.

                             Example:

                             var
                               FileName : string;

                             {This function gets a temporary file name form the system}
                             function GetTemporaryFileName : string;
                             {$IFNDEF WIN32}
                               const MAX_PATH = 144;
                             {$ENDIF}
                             var
                              {$IFDEF WIN32}
                               lpPathBuffer : PChar;
                              {$ENDIF}
                               lpbuffer : PChar;
                             begin
                              {Get the file name buffer}
                               GetMem(lpBuffer, MAX_PATH);
                              {$IFDEF WIN32}
                              {Get the temp path buffer}
                               GetMem(lpPathBuffer, MAX_PATH);
                              {Get the temp path}
                               GetTempPath(MAX_PATH, lpPathBuffer);
                              {Get the temp file name}
                               GetTempFileName(lpPathBuffer,
                                               'tmp',
                                               0,
                                               lpBuffer);
                              {Free the temp path buffer}
                               FreeMem(lpPathBuffer, MAX_PATH);
                              {$ELSE}
                              {Get the temp file name}
                               GetTempFileName(GetTempDrive('C'),
                                               'tmp',
                                               0,
                                               lpBuffer);
                              {$ENDIF}
                              {Create a pascal string containg}
                              {the temp file name and return it}
                               result := StrPas(lpBuffer);
                              {Free the file name buffer}
                               FreeMem(lpBuffer, MAX_PATH);
                             end;

                             {Read a AVI file into a blob field}
                             procedure TForm1.Button1Click(Sender: TObject);
                             var
                               FileStream: TFileStream; {to load the avi file}
                               BlobStream: TBlobStream; {to save to the blob}
                             begin
                              {Allow the button to repaint}
                               Application.ProcessMessages;
                              {Turn off the buttons}
                               Button1.Enabled := false;
                               Button2.Enabled := false;
                              {Assign the avi file name to read}
                               FileStream := TFileStream.Create(
                                 'C:\PROGRA~1\BORLAND\DELPHI~1\DEMOS\COOLSTUF\COOL.AVI',
                                 fmOpenRead);
                               Table1.Edit;
                              {Create a BlobStream for the field Table1AVI}
                               BlobStream := TBlobStream.Create(Table1AVI, bmReadWrite);
                              {Seek to the Begginning of the stream}
                               BlobStream.Seek(0, soFromBeginning);
                              {Delete any data that may be there}
                               BlobStream.Truncate;
                              {Copy from the FileStream to the BlobStream}
                               BlobStream.CopyFrom(FileStream, FileStream.Size);
                              {Free the streams}
                               FileStream.Free;
                               BlobStream.Free;
                              {Post the record}
                               Table1.Post;
                              {Enable the buttons}
                               Button1.Enabled := true;
                               Button2.Enabled := true;
                             end;

                             {Read a avi stored in a blob, and play it}
                             procedure TForm1.Button2Click(Sender: TObject);
                             var
                               FileStream: TFileStream; {a temp file}
                               BlobStream: TBlobStream; {the AVI Blob}
                             begin
                              {Create a blob stream for the AVI blob}
                               BlobStream := TBlobStream.Create(Table1AVI, bmRead);
                               if BlobStream.Size = 0 then begin
                                BlobStream.Free;
                                Exit;
                               end;
                              {Close the media player}
                               MediaPlayer1.Close;
                              {Reset the file name}
                               MediaPlayer1.FileName := '';
                              {Refresh the play window}
                               MediaPlayer1.Display := Panel1;
                               Panel1.Refresh;
                              {if we have a temp file then erase it}
                               if FileName <> '' then
                                 DeleteFile(FileName);
                              {Get a temp file name}
                               FileName := GetTemporaryFileName;
                              {Create a temp file stream}
                               FileStream := TFileStream.Create(FileName,
                                                                fmCreate or fmOpenWrite);
                              {Copy the blob to the temp file}
                               FileStream.CopyFrom(BlobStream, BlobStream.Size);
                              {Free the streams}
                               FileStream.Free;
                               BlobStream.Free;
                              {Setup the Medai player to play the AVI file}
                               MediaPlayer1.FileName := filename;
                               MediaPlayer1.DeviceType := dtAviVideo;
                               MediaPlayer1.Open;
                               MediaPlayer1.Play;
                             end;

                             procedure TForm1.FormDestroy(Sender: TObject);
                             begin
                              {Unassign the temp file from the media player}
                               MediaPlayer1.Close;
                               MediaPlayer1.FileName := '';
                              {Erase the temp file}
                               if FileName <> '' then
                                 DeleteFile(FileName);
                             end;

                             Joe
                             --
                             Joe C. Hecht
                             joehecht@gte.net

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360101
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360102
And t_medhat is it working?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question