Page 1 of 1

Saving audio files in a blobfield

PostPosted: August 5th, 2007, 6:37 am
by Tom Duncan
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

PostPosted: August 5th, 2007, 8:05 am
by Kambiz
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

Fixed

PostPosted: August 5th, 2007, 10:07 pm
by Tom Duncan
Thanks Kambiz,

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

Tom :D

PostPosted: August 6th, 2007, 12:35 pm
by Tom Duncan
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