Open memory stream.
function OpenStream(Buffered: Integer; Managed: Integer; MemStream: Pointer; StreamSize: Cardinal; Format: TStreamFormat): Boolean;
Parameters |
Description |
Buffered: Integer |
Specifies if stream is buffered stream. True specifies buffered stream. False specifies non bufferd stream. |
Managed: Integer |
Specifies if stream is dynamic or static. True specifies dynamic stream. False specifies static stream. |
MemStream: Pointer |
Reference of memory block with stream data. |
StreamSize: Cardinal |
Size of memory block, in bytes. |
Format: TStreamFormat |
Stream format. This value can't be sfAutodetect. You must specify valid stream format. |
Return Values |
Description |
True |
All OK. |
False |
Error. To get error message read here. |
First block of data needs to be large enough and must contain all data to identify specified stream type.
For sfMp3 stream format, this block of data needs to contain at least one valid mp3 frame.
For sfOgg streamformat, this block must contain enough data to identify ogg type.
For sfWave, this block must contain valid RIFF header.
If this function fails, call this function again with larger block of data or with another block of data.
For sfMp3 stream, 128 kbps at 44100 Hz you need at least 426 bytes without ID3v2 data at stream start. If input block is too small, function will fail. Then you need to send larger block.
Buffered stream allocates internal memory for input data and class makes copy of input data. User can destroy input data because there is copy of this data in internal buffer. Class will manage this internal memory.
If stream is not buffered, function takes only pointer to stream data. User is responsible for this data. So, user must keep this data in memory until function is done with this data. See IsStreamDataFree.
If you specify dynamic stream, you can add new data into this stream with PushDataToStream function. Use OpenStream with small chunk of input data and add rest of data with PushDataToStream function later. Use SetCallbackFunc and callback mechanism to determine when class needs more data. You can't seek or use reverse mode on dynamic stream. If dynamic stream runs out of data, it waits for new data, playing is paused, wave output is still active and class is ready to continue playing when you push new data to stream with PushDataToStream.
If stream is not dynamic, you can't add new data into stream. Class will use only data provided by sMemStream parameter. But this type of stream has no limitation in seek and reverse mode. When this stream runs out of data, playing is stopped.
Open static stream.
var format: TStreamFormat; begin InitInfo(Form1); Timer1.Enabled := true; Timer2.Enabled := true; if(OpenDialog1.Execute()) then begin format := player.GetFileFormat(OpenDialog1.FileName); if(format = sfUnknown) then begin MessageBox(0, PAnsiChar(player.GetError()), 'Fatal error' ,0); Exit; end; player.Close(); if Buffer <> NIL then begin FreeMemory(Buffer); Buffer := NIL; end; if FileHandle <> 0 then begin FileClose(FileHandle); FileHandle := 0; end; FileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead); FileSize := FileSeek(FileHandle,0,2); FileSeek(FileHandle,0,0); GetMem(Buffer, FileSize + 1); FileRead(FileHandle, Buffer^, FileSize); FileClose(FileHandle); FileHandle := 0; if player.OpenStream(1, 0, Buffer, FileSize, format) then begin SetInfo(Form1); player.STartPlayback; end else MessageBox(0, PAnsiChar(player.GetError()), 'Fatal error' ,0); end; end;
Copyright (c) 2010. Zoran Cindori - All rights reserved.
Web: http://libzplay.sourceforge.net/ Email: zcindori@inet.hr |