Saving audio files in a blobfield

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Saving audio files in a blobfield

Postby Tom Duncan » August 5th, 2007, 6:37 am

Hi all,
I am creating a project which requires me to save wave files in database blob fields.
I will then play these files with StockAudioPlayer.

Here is the code so far.

Code: Select all
procedure TfrmEdit.BitBtn2Click(Sender: TObject);
var
  FS: TFileStream;
  Adapter: TwaveStreamAdapter;
begin
  OpenD.InitialDir:= Master.Masters;
  OpenD.FileName:= frmMain.kPage.FieldByName('Sname').asString;
  if OpenD.Execute then begin
    with frmMain.kPage do begin
      Edit;
      FieldByName('Sname').asString:= OpenD.FileName;
      // Now put audio into Blob field
      FS := TFileStream.Create(OpenD.FileName, fmOpenRead);
      try
        FS := CreateBlobStream(FieldByName('Sound'),bmReadWrite);
        Adapter := TwaveStreamAdapter.Create(FS, soReference);
        FieldByName('FrameD').asInteger:= Adapter.Length div 100;
        FieldByName('TtlDur').asInteger:= Adapter.Length div 100;
      finally
        Adapter.Free;
        FS.Free;
      end;
      Post;
    end;
    BuildPreview(P1);
    TlinePos:=0;
    CheckIfVisible(P1);
  end;
end;


I get an error Incompatable types Tfilestream and Tstream.

How can I convert a filestream to a stream?

Tom
Tom Duncan
Member
Member
 
Posts: 3
Joined: August 5th, 2007, 6:32 am

Postby Kambiz » August 5th, 2007, 8:05 am

The procedure is straight forward and you do not need to use a TBlobStream or TWaveStreamAdapter object.

TBlobField.LoadFromFile is the method you should call.

By the way, take a look at the following topic:
http://forum.delphiarea.com/viewtopic.php?t=1076
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Fixed

Postby Tom Duncan » August 5th, 2007, 10:07 pm

Thanks Kambiz,

Fixed with (fieldByName('Sound') as TBlobField).LoadFromFile(OpenD.FileName);

Tom :D
Tom Duncan
Member
Member
 
Posts: 3
Joined: August 5th, 2007, 6:32 am

Postby Tom Duncan » August 6th, 2007, 12:35 pm

When I played from a filesteam from my database I kept getting illegal messages.
I was using the multimedia Timer.
Changed to a normal timer and set Async to true and fixed all.

Any ideas anyone.

Tom
Tom Duncan
Member
Member
 
Posts: 3
Joined: August 5th, 2007, 6:32 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron