Open memory stream.
Public Function OpenStream(ByVal Buffered As Boolean, ByVal Dynamic As Boolean, ByRef MemStream() As Byte, ByVal StreamSize As UInteger, ByVal nFormat As TStreamFormat) As Boolean
Parameters |
Description |
ByVal Buffered As Boolean |
Specifies if stream is buffered stream. True specifies buffered stream. False specifies non bufferd stream. |
ByVal Dynamic As Boolean |
Specifies if stream is dynamic or static. True specifies dynamic stream. False specifies static stream. |
ByRef MemStream() As Byte |
Reference of memory block with stream data. |
ByVal StreamSize As UInteger |
Size of memory block, in bytes. |
ByVal nFormat As 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.
Dim format As TStreamFormat = player.GetFileFormat(OpenFileDialog1.FileName) Dim fInfo As New System.IO.FileInfo(OpenFileDialog1.FileName) Dim numBytes As Long = fInfo.Length Dim fStream As New System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read) Dim br As New System.IO.BinaryReader(fStream) Dim stream_data() As Byte = Nothing stream_data = br.ReadBytes(CInt(Fix(numBytes))) If Not (player.OpenStream(True, False, stream_data, CUInt(numBytes), format)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) End If br.Close() fStream.Close()
Copyright (c) 2010. Zoran Cindori - All rights reserved.
Web: http://libzplay.sourceforge.net/ Email: zcindori@inet.hr |