Solved

inserting avi clip in data field

Posted on 1998-03-05
3
312 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi custom sort exception 6 136
Convert Jpg /PNG To GIF 5 120
can't find the executable in Simulator 1 80
Controlled Assessment GCSE - desperate help needed 4 76
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now