Solved

inserting avi clip in data field

Posted on 1998-03-05
3
337 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
[X]
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
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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