public URLPlayback() { this.FileProc = new BASS_FILEPROCS( new FILECLOSEPROC(this.FileProc_Close), new FILELENPROC(this.FileProc_Length), new FILEREADPROC(this.FileProc_Read), new FILESEEKPROC(this.FileProc_Seek) ); } private void Download(IntPtr Buffer, int Length, IntPtr User) { byte[] Buf = new byte[Length]; if (Buffer != IntPtr.Zero) { Marshal.Copy(Buffer, Buf, 0, Length); } if (this.Storage != null) this.Storage.Write(Buf, 0, Length); } public override bool Open(dynamic Source) { this.FreeStream(); //Clearing MemoryStream to delete old data this.Source = Source; this.Downloader = new DOWNLOADPROC(Download); this.Storage = new MemoryStream(); //Recreating MemoryStream this.DownloadStream = Bass.BASS_StreamCreateURL(Source, 0, BASSFlag.BASS_STREAM_STATUS, this.Downloader, (IntPtr) 0); if (this.DownloadStream == 0) { this.WriteErrorCode(); return false; } bool Ready = false; while (!Ready) { int CurrentPuffer = (int)Bass.BASS_StreamGetFilePosition(this.lStream, BASSStreamFilePosition.BASS_FILEPOS_BUFFER); int TotalPuffer = (int)Bass.BASS_StreamGetFilePosition(this.lStream, BASSStreamFilePosition.BASS_FILEPOS_END); int PufferLoadInPercent = CurrentPuffer * 100 / TotalPuffer; if (PufferLoadInPercent == 100) { this.GetTags(); Ready = true; } } this.lStream = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_BUFFER, BASSFlag.BASS_DEFAULT, this.FileProc, IntPtr.Zero); Bass.BASS_ChannelPlay(this.DownloadStream, false); Bass.BASS_ChannelSetAttribute(this.DownloadStream, BASSAttribute.BASS_ATTRIB_VOL, 0); return true; } private long FileProc_Length(IntPtr User) { return 0; } private void FileProc_Close(IntPtr User) { if (this.Storage != null) { this.Storage.Close(); } } private int FileProc_Read(IntPtr Buffer, int Length, IntPtr User) { if (this.Storage == null) { return 0; } try { byte[] Data = new Byte[Length]; int BytesRead = this.Storage.Read(Data, 0, Length); Marshal.Copy(Data, 0, Buffer, BytesRead); return BytesRead; } catch { return 0; } } private bool FileProc_Seek(long Position, IntPtr User) { if (this.Storage == null) { return false; } try { long Pos = this.Storage.Seek(Position, SeekOrigin.Begin); return true; } catch { return false; } }