Antonio DieS писал(а):
это то что я думаю да ? про следующию песню то что ты говорил?Да
А нифига не получается тормоза убрать. Вот эта функция -- BASS_StreamCreateURL, страшно тормозит при работе.
------------ Дoбавленo:
Вот так можно немного убрать, но не шибко сильно
Add(MainForm,16107315,56,56)
{
Left=20
Top=105
Width=438
Height=181
}
Add(Button,16530932,49,175)
{
Left=195
Top=120
TabOrder=-1
Caption="Read"
link(onClick,10076048:doEvent1,[])
}
Add(InlineCode,16713139,245,189)
{
WorkPoints=#6:doRead|
EventPoints=#13:onStreamTitle|11:onStreamURL|15:onBroadcastName|9:onBitrate|10:onProgress|8:onStatus|5:onEnd|7:onError|
VarPoints=#6:Handle|
DataPoints=#3:URL|8:StrProxy|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|34:uses Windows,kol,Share,Debug,Bass;|0:|5:const|48: // BASS_ChannelGetTags types : what's returned|57: BASS_TAG_ID3 = 0; // ID3v1 tags : 128 byte block|64: BASS_TAG_ID3V2 = 1; // ID3v2 tags : variable length block|78: BASS_TAG_OGG = 2; // OGG comments : series of null-terminated strings|78: BASS_TAG_HTTP = 3; // HTTP headers : series of null-terminated strings|77: BASS_TAG_ICY = 4; // ICY headers : series of null-terminated strings|67: BASS_TAG_META = 5; // ICY metadata : null-terminated string|66: BASS_TAG_VENDOR = 9; // OGG encoder : null-terminated string|58: BASS_TAG_LYRICS3 = 10; // Lyric3v2 tag : ASCII string|88: BASS_TAG_RIFF_INFO = $100; // RIFF/WAVE tags : series of null-terminated ANSI strings|63: BASS_TAG_MUSIC_NAME = $10000; // MOD music name : ANSI string|63: BASS_TAG_MUSIC_MESSAGE = $10001; // MOD message : ANSI string|84: BASS_TAG_MUSIC_INST = $10100; // + instrument #, MOD instrument name : ANSI string|78: BASS_TAG_MUSIC_SAMPLE = $10300; // + sample #, MOD sample name : ANSI string|0:|30: // BASS_SetConfigPtr options|33: BASS_CONFIG_NET_AGENT = 16;|33: BASS_CONFIG_NET_PROXY = 17;|0:|37: // BASS_StreamGetFilePosition modes|30: BASS_FILEPOS_CURRENT = 0;|49: BASS_FILEPOS_DECODE = BASS_FILEPOS_CURRENT;|30: BASS_FILEPOS_DOWNLOAD = 1;|30: BASS_FILEPOS_END = 2;|30: BASS_FILEPOS_START = 3;|30: BASS_FILEPOS_CONNECTED = 4;|30: BASS_FILEPOS_BUFFER = 5;|0:|27: // BASS_SetConfig options|32: BASS_CONFIG_BUFFER = 0;|32: BASS_CONFIG_UPDATEPERIOD = 1;|32: BASS_CONFIG_GVOL_SAMPLE = 4;|32: BASS_CONFIG_GVOL_STREAM = 5;|32: BASS_CONFIG_GVOL_MUSIC = 6;|32: BASS_CONFIG_CURVE_VOL = 7;|32: BASS_CONFIG_CURVE_PAN = 8;|32: BASS_CONFIG_FLOATDSP = 9;|33: BASS_CONFIG_3DALGORITHM = 10;|33: BASS_CONFIG_NET_TIMEOUT = 11;|33: BASS_CONFIG_NET_BUFFER = 12;|33: BASS_CONFIG_PAUSE_NOPLAY = 13;|33: BASS_CONFIG_NET_PREBUF = 15;|33: BASS_CONFIG_NET_PASSIVE = 18;|33: BASS_CONFIG_REC_BUFFER = 19;|33: BASS_CONFIG_NET_PLAYLIST = 21;|33: BASS_CONFIG_MUSIC_VIRTUAL = 22;|33: BASS_CONFIG_VERIFY = 23;|33: BASS_CONFIG_UPDATETHREADS = 24;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|16: th:PThread;|20: StrURL: string;|19: procedure Err;|46: function _OnExec(Sender:PThread):Integer;|24: procedure SyncExec;|9: public|30: onStreamTitle: THI_Event;|33: onStreamURL: THI_Event; |32: onBroadcastName: THI_Event;|31: onBitrate: THI_Event; |27: onProgress: THI_Event;|25: onStatus: THI_Event;|27: onEnd: THI_Event; |24: onError: THI_Event;|20: URL: THI_Event;|25: StrProxy: THI_Event;|0:|34: destructor Destroy; override;|51: procedure doRead(var _Data:TData; Index:word);|51: procedure Handle(var _Data:TData; Index:word);|0:|5: end;|0:|3:var|46: Proxy: array [0..99] of char; //proxy server|21: cthread: DWORD = 0;|20: chan: HSTREAM = 0;|0:|14:implementation|0:|96:function BASS_ChannelGetTags(handle: HSTREAM; tags: DWORD): PChar; stdcall; external 'bass.dll';|94:function BASS_SetConfigPtr(option: DWORD; value: Pointer): BOOL; stdcall; external 'bass.dll';|0:|5:const|48: urls: array[0..9] of string = ( // stream URLs|108: 'http://www.radioparadise.com/musiclinks/rp_128-9.m3u','http://www.radioparadise.com/musiclinks/rp_32.m3u',|81: 'http://www.sky.fm/mp3/classical.pls','http://www.sky.fm/mp3/classical_low.pls',|75: 'http://www.sky.fm/mp3/the80s.pls','http://www.sky.fm/mp3/the80s_low.pls',|98: 'http://bassdrive.com/v2/streams/BassDrive.m3u','http://bassdrive.com/v2/streams/BassDrive3.m3u',|74: 'http://somafm.com/secretagent.pls','http://somafm.com/secretagent24.pls'|6: );|0:|31:destructor THiAsmClass.Destroy;|5:begin|38: if th <> nil then free_and_nil(th);|13: BASS_Free;|13: inherited;|4:end;|0:|26:procedure THiAsmClass.Err;|5:begin|3:TRY|38: if BASS_ErrorGetCode = 0 then exit;|13: BASS_Free;|7:FINALLY|51: _hi_OnEvent(onError,integer(BASS_ErrorGetCode));|7:END; |4:end;|0:|29:function THiAsmClass._OnExec;|5:begin|39: while not Sender.Terminated do begin|35: Sender.Synchronize(SyncExec);|7: end;|15: Result := 0;|4:end;|0:|31:procedure THiAsmClass.SyncExec;|17:var icy: PChar;|27: Len, Progress: DWORD;|0:|65:procedure StatusProc(buffer: Pointer; len, user: DWORD); stdcall;|5:begin|39: if (buffer <> nil) and (len = 0) then|59: _hi_onEvent(THiAsmClass(user).onStatus, PChar(buffer));|4:end;|0:|30:procedure DoMeta(user: DWORD);|18:var meta: PChar;|17: p: Integer;|18: str :string;|5:begin|52: meta := BASS_ChannelGetTags(chan, BASS_TAG_META);|30: if (meta <> nil) then begin|37: p := Pos('StreamTitle=', meta);|27: if (p = 0) then Exit;|18: p := p + 13;|90: _hi_onEvent(THiAsmClass(user).onStreamTitle, Copy(meta, p, Pos(';', meta) - p - 1));|59: str := Copy(meta, Pos(';', meta) + 1, Length(meta)); |34: p := Pos('StreamUrl=', str);|27: if (p = 0) then Exit;|18: p := p + 11;|86: _hi_onEvent(THiAsmClass(user).onStreamURL, Copy(str, p, Pos(';', str) - p - 1));|6: end;|4:end;|0:|71:procedure MetaSync(handle: HSYNC; channel, data, user: DWORD); stdcall;|5:begin|15: DoMeta(user);|4:end;|0:|5:begin|3:TRY|17: progress := 0;|45: BASS_StreamFree(chan); // close old stream|98: chan := BASS_StreamCreateURL(PChar(StrURL), 0, BASS_STREAM_STATUS, @StatusProc, LongInt(Self));|27: if (chan = 0) then begin|10: Err;|11: exit;|17: end else begin|12: repeat|67: len := BASS_StreamGetFilePosition(chan, BASS_FILEPOS_END);|90: if (len = DW_Error) then break; // something's gone wrong! (eg. BASS_Free called)|79: progress := (BASS_StreamGetFilePosition(chan, BASS_FILEPOS_DOWNLOAD) -|92: BASS_StreamGetFilePosition(chan, BASS_FILEPOS_CURRENT)) * 100 div len;|52: _hi_onEvent(onProgress, integer(progress));|26: until progress > 75;|43: // get the broadcast name and bitrate|53: icy := BASS_ChannelGetTags(chan, BASS_TAG_ICY);|25: if (icy = nil) then|82: icy := BASS_ChannelGetTags(chan, BASS_TAG_HTTP); // no ICY tags, try HTTP|29: if (icy <> nil) then|36: while (icy^ <> #0) do begin|51: if (Copy(icy, 1, 9) = 'icy-name:') then|78: _hi_onEvent(onBroadcastName, Copy(icy, 10, MaxInt)) |54: else if (Copy(icy, 1, 7) = 'icy-br:') then|61: _hi_onEvent(onBitrate, Copy(icy, 8, MaxInt)); |41: icy := icy + Length(icy) + 1;|13: end;|62: // get the stream title and set sync for subsequent titles|26: DoMeta(LongInt(Self));|63: BASS_ChannelSetSync(chan, BASS_SYNC_META, 0, @MetaSync, 0);|15: // play it!|23: _hi_onEvent(onEnd);|29:// Applet.ProcessMessages;|36:// BASS_ChannelPlay(chan, FALSE);|7: end;|7:FINALLY|40: if Assigned(th) then free_and_nil(th);|4:END;|4:end;|0:|29:procedure THiAsmClass.doRead;|19:var str : string;|5:begin|0:|64:// if (not BASS_Init(-1, 44100, 0, ReadHandle, nil)) then begin|11:// Err;|45:// if Assigned(th) then free_and_nil(th);|12:// exit;|11:// end; |37: StrURL := ReadString(_Data, URL); |0:|77: BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1); // enable playlist processing|123: BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 0); // minimize automatic pre-buffering, so we can do it (and display it) instead|0:|39: str := ReadString(_Data, StrProxy); |26: if str <> '' then begin|69: StrPCopy(proxy, str); // copy the Servertext to the Proxy array|75: BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY, @proxy[0]) // enable proxy |11: end else|71: BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY, nil); // disable proxy |0:|34: if not Assigned(th) then begin |64: th := {$ifdef F_P}NewThreadforFPC{$else}NewThread{$endif};|30: th.OnExecute := _OnExec;|16: th.Resume;|7: end;|4:end;|0:|29:procedure THiAsmClass.Handle;|5:begin|26: dtInteger(_Data, chan);|4:end;|4:end.|
link(onStreamTitle,8835573:doText,[(321,195)(321,167)])
link(URL,10286761:Value,[])
link(onStreamURL,16345409:doText,[])
link(onBroadcastName,11552554:doText,[(321,209)(321,237)])
link(onBitrate,606815:doText,[(321,216)(321,272)])
link(onProgress,15665858:doProcessMessages,[])
link(onStatus,57426:doText,[(321,230)(321,307)])
}
Add(Memory,5897771,406,84)
{
@Hint=#11:mp3 -- File|
Default=String(http://slil.ru/25901566/41cee41a.4858e470/John_B_-_03_-_Concord_Dawn_-_Morning_Light.mp3)
}
Add(Memory,14181987,364,84)
{
@Hint=#11:m3u -- List|
Default=String(http://www.radioparadise.com/musiclinks/rp_128-9.m3u)
}
Add(Memory,10286761,245,140)
{
@Hint=#11:m3u -- List|
Default=String(http://www.radioparadise.com/musiclinks/rp_128-9.m3u)
}
Add(Hub,10076048,105,175)
{
OutCount=4
link(onEvent1,1861628:doInit,[(159,181)(159,146)])
link(onEvent2,1861628:doStart,[(159,188)(159,153)])
link(onEvent3,16713139:doRead,[])
}
Add(BASS_Global,1861628,182,140)
{
}
Add(Edit,8835573,364,161)
{
Left=100
Top=10
Width=325
Text=""
}
Add(Edit,16345409,364,196)
{
Left=100
Top=35
Width=325
Text=""
}
Add(Label,6657059,217,56)
{
Left=5
Top=15
Width=90
Height=17
Caption="StreamTitle:"
AutoSize=1
Alignment=1
}
Add(Label,10095235,112,56)
{
Left=5
Top=40
Width=90
Height=17
Caption="StreamURL:"
AutoSize=1
Alignment=1
}
Add(Label,3164710,182,56)
{
Left=5
Top=65
Width=90
Height=17
Caption="Broad:CastName:"
AutoSize=1
Alignment=1
}
Add(Edit,11552554,364,231)
{
Left=100
Top=60
Width=325
Text=""
}
Add(Edit,606815,364,266)
{
Left=100
Top=85
Width=65
Text=""
}
Add(Label,6155548,147,56)
{
Left=5
Top=90
Width=90
Height=17
Caption="Bitrate:"
AutoSize=1
Alignment=1
}
Add(Edit,57426,364,301)
{
Left=265
Top=85
Width=160
Text=""
}
Add(Label,7455734,252,56)
{
Left=170
Top=90
Width=90
Height=17
Caption="Status:"
AutoSize=1
Alignment=1
}
Add(Application,15665858,413,217)
{
Wait=1
}