Show / Hide Table of Contents

Delegate DownloadProcedure

Internet stream download callback function (to be used with CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr)).

Extensions
Stream an MP3 file, and save a local copy.

var file = new FileStream("afile.mp3", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
byte[] _buffer;

...

void MyDownloadProc(IntPtr buffer, int length, IntPtr user)
{
    if (buffer == IntPtr.Zero)
    {
        // finished downloading
        file.Close();
        return;
    }

    if (_buffer == null || _buffer.Length < length)
        _buffer = new byte[length];

    Marshal.Copy(buffer, _buffer, 0, length);

    File.Write(_buffer, 0, length);
}

...

var stream = Bass.CreateStream("http://www.asite.com/afile.mp3", 0, 0, MyDownloadProc, IntPtr.Zero);
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.dll
Syntax
public delegate void DownloadProcedure(IntPtr Buffer, int Length, IntPtr User);
Parameters
IntPtr Buffer

The pointer to the Buffer containing the downloaded data... = finished downloading.

Int32 Length

The number of bytes in the Buffer... 0 = HTTP or ICY tags.

IntPtr User

The User instance data given when CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr) was called.

Remarks

The callback will be called before the CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr) call returns (if it's successful), with the initial downloaded data. So any initialization (eg. creating the file if writing to disk) needs to be done either before the call, or in the callback function.

When the StreamStatus flag is specified in the CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr) call, HTTP and ICY tags may be passed to the callback during connection, before any stream data is received. The tags are given exactly as would be returned by ChannelGetTags(Int32, TagType). You can destinguish between HTTP and ICY tags by checking what the first string starts with ("HTTP" or "ICY").

A download callback function could be used in conjunction with a MetadataReceived sync set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to save individual tracks to disk from a Shoutcast stream.

Back to top Copyright © 2017 Mathew Sachin
Generated by DocFx