Board index » delphi » please help me, trying to get (mp3)blob from a db

please help me, trying to get (mp3)blob from a db


2005-01-04 11:40:16 AM
delphi29
I am having a hard time loading in a MP3 from a database, I created using
access and now Im using delphi 6 to to get the data.
heres the code
procedure TForm1.DBLookupListBox1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
bM :TADOBlobStream;//blob mp3
mp3File:String; //mp3 file
MemSize : integer;
FDataP : Pointer;
begin
bM:=TADOBlobStream.Create(ADOTable1Sound, bmRead);
MemSize := bM.Size;
if MemSize=0 then
begin
MessageDlg('Theres no Mp3 file present',mtInformation,[mbOK],0);
bM.free;
exit;
end;
try
//heres where the problem begins...................................
// LoadFromStream(bM);
// FDataP := AllocMem(MemSize);
// bM.Read(FDataP^, MemSize);
mp3player.Close; //making sure no mp3 is playing
mp3player.FileName:= LoadFromStream(bM);
mp3player.Open;
bM.Free; // free up space....
end;
How do I retrive the mp3 blob and create and memory spot for it . Then I
will play the mp3 file. Then I need to remove the allocated memory for the
mp3.
 
 

Re:please help me, trying to get (mp3)blob from a db

I would think mp3player.FileName would be expecting a string rather than a
blob.
Maybe try saving the blob to a file then setting the mp3player.FileName to
the name of that file.
Andy
"Gilbert" <XXXX@XXXXX.COM>writes
Quote
I am having a hard time loading in a MP3 from a database, I created using
access and now Im using delphi 6 to to get the data.

heres the code

procedure TForm1.DBLookupListBox1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
bM :TADOBlobStream;//blob mp3
mp3File:String; //mp3 file
MemSize : integer;
FDataP : Pointer;
begin

bM:=TADOBlobStream.Create(ADOTable1Sound, bmRead);
MemSize := bM.Size;
if MemSize=0 then
begin
MessageDlg('Theres no Mp3 file present',mtInformation,[mbOK],0);
bM.free;
exit;
end;
try
//heres where the problem begins...................................
// LoadFromStream(bM);
// FDataP := AllocMem(MemSize);
// bM.Read(FDataP^, MemSize);
mp3player.Close; //making sure no mp3 is playing
mp3player.FileName:= LoadFromStream(bM);
mp3player.Open;
bM.Free; // free up space....
end;

How do I retrive the mp3 blob and create and memory spot for it . Then I
will play the mp3 file. Then I need to remove the allocated memory for the
mp3.


 

Re:please help me, trying to get (mp3)blob from a db

How do i save the file from the blob, with out saving it to the c drive
"Andy" <XXXX@XXXXX.COM>writes
Quote
I would think mp3player.FileName would be expecting a string rather than a
blob.
Maybe try saving the blob to a file then setting the mp3player.FileName to
the name of that file.

Andy
"Gilbert" <XXXX@XXXXX.COM>writes
news:41da104e$XXXX@XXXXX.COM...
>I am having a hard time loading in a MP3 from a database, I created
using
>access and now Im using delphi 6 to to get the data.
>
>heres the code
>
>procedure TForm1.DBLookupListBox1MouseDown(Sender: TObject;
>Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
>var
>bM :TADOBlobStream;//blob mp3
>mp3File:String; //mp3 file
>MemSize : integer;
>FDataP : Pointer;
>begin
>
>bM:=TADOBlobStream.Create(ADOTable1Sound, bmRead);
>MemSize := bM.Size;
>if MemSize=0 then
>begin
>MessageDlg('Theres no Mp3 file present',mtInformation,[mbOK],0);
>bM.free;
>exit;
>end;
>try
>//heres where the problem begins...................................
>// LoadFromStream(bM);
>// FDataP := AllocMem(MemSize);
>// bM.Read(FDataP^, MemSize);
>mp3player.Close; //making sure no mp3 is playing
>mp3player.FileName:= LoadFromStream(bM);
>mp3player.Open;
>bM.Free; // free up space....
>end;
>
>How do I retrive the mp3 blob and create and memory spot for it . Then I
>will play the mp3 file. Then I need to remove the allocated memory for
the
>mp3.
>
>


 

Re:please help me, trying to get (mp3)blob from a db

does the mp3Player component have a LoadFromStream or LoadFromBlob
capability ?
Andy
"Gilbert" <XXXX@XXXXX.COM>writes
Quote
How do i save the file from the blob, with out saving it to the c drive
"Andy" <XXXX@XXXXX.COM>writes
news:41da3c31$XXXX@XXXXX.COM...
>I would think mp3player.FileName would be expecting a string rather than
>a
>blob.
>Maybe try saving the blob to a file then setting the mp3player.FileName
>to
>the name of that file.
>
>Andy
>"Gilbert" <XXXX@XXXXX.COM>writes
>news:41da104e$XXXX@XXXXX.COM...
>>I am having a hard time loading in a MP3 from a database, I created
using
>>access and now Im using delphi 6 to to get the data.
>>
>>heres the code
>>
>>procedure TForm1.DBLookupListBox1MouseDown(Sender: TObject;
>>Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
>>var
>>bM :TADOBlobStream;//blob mp3
>>mp3File:String; //mp3 file
>>MemSize : integer;
>>FDataP : Pointer;
>>begin
>>
>>bM:=TADOBlobStream.Create(ADOTable1Sound, bmRead);
>>MemSize := bM.Size;
>>if MemSize=0 then
>>begin
>>MessageDlg('Theres no Mp3 file present',mtInformation,[mbOK],0);
>>bM.free;
>>exit;
>>end;
>>try
>>//heres where the problem begins...................................
>>// LoadFromStream(bM);
>>// FDataP := AllocMem(MemSize);
>>// bM.Read(FDataP^, MemSize);
>>mp3player.Close; //making sure no mp3 is playing
>>mp3player.FileName:= LoadFromStream(bM);
>>mp3player.Open;
>>bM.Free; // free up space....
>>end;
>>
>>How do I retrive the mp3 blob and create and memory spot for it . Then
>>I
>>will play the mp3 file. Then I need to remove the allocated memory for
the
>>mp3.
>>
>>
>
>


 

Re:please help me, trying to get (mp3)blob from a db

I use this code and it works fine....
use MMSystem,shellAPI
procedure TFMain.PlayClick(Sender: TObject);
var
B: TADOBlobStream;
M: TMemoryStream;
begin
dmdata.tblSounds.open; //table with mp3-blob
// create blob stream
B := TADOBlobStream.Create(dmData.tblSoundsWave, bmRead);
Screen.Cursor := crHourGlass; // wait hourglass
try
M := TMemoryStream.Create; // create memory stream
try
M.CopyFrom(B, B.Size); // copy from blob to memory stream
// Attempt to play sound. Raise exception if something goes wrong
Win32Check(PlaySound(M.Memory, 0, SND_SYNC or SND_MEMORY));
finally
M.Free;
end;
finally
Screen.Cursor := crDefault;
B.Free; // clean up
end;
end;
--- posted by geoForum on delphi.newswhat.com