0
0

Hello all!

I will play an mp3 directly from a zip file.
I have zipmaster for delphi which supports
streaming.

so i will give this created stream to fmod to play it, but the openfile function doesnt work :/ .. i would need something like playfromstream or so…

is there any way to do that!?

any help would be very great,

thanks!!
spitron
spitron@yahoo.com

  • You must to post comments
0
0

Write your own file callback functions to support streams in Delphi. This should not be too difficult, but if you have any major problems, let me know and I’ll be able to make a small sample application for you.

  • You must to post comments
0
0

Here is a tested and working implementation of file callbacks in Delphi to use streams.
<pre>function OpenCallback(Name: PChar): Cardinal; cdecl;
var
Stream: TFileStream;
begin
// Open a filestream to the given filename
Stream := TFileStream.Create(String(Name), fmOpenRead or fmShareDenyNone);
// Return the pointer to the filestream as the file handle
Result := Cardinal(Stream);
end;

procedure CloseCallback(Handle: Cardinal); cdecl;
begin
// The handle is the pointer to the filestream
TFileStream(Handle).Free;
end;

function ReadCallback(Buffer: Pointer; Size: Cardinal; Handle: Cardinal): Cardinal; cdecl;
begin
// Read Size bytes into Buffer and return the actual number of bytes read
Result := TFileStream(Handle).Read(Buffer^, Size);
end;

procedure SeekCallback(Handle: Cardinal; Pos: Cardinal; Mode: Byte); cdecl;
begin
// Seek to the given position in the stream
// Mode 0 = soFromBeginning, 1 = soFromCurrent, 2 = soFromEnd
TFileStream(Handle).Seek(Pos, Mode);
end;

function TellCallback(Handle: Cardinal): Cardinal; cdecl;
begin
// Return the current position in the stream
Result := TFileStream(Handle).Position;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
FSOUND_File_SetCallbacks(OpenCallback, CloseCallback, Readcallback, SeekCallback, TellCallback);
FSOUND_Init(22050, 128, 0);
end;</pre>In the process of testing this, I found a small bug in my translation of the FMOD headers. The Seek callback has a Byte parameter that is incorrectly specified as ByteBool. This is on line 56 of fmod.pas.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.