1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182:
| procedure StatusProc(buffer: Pointer; len, user: DWORD); stdcall; begin if (buffer <> nil) and (len = 0) then SendMessage(win, WM_INFO_UPDATE, 8, DWORD(PChar(buffer))) else WaveStream.Write(buffer^, len); end;
function OpenURL(url: PChar): Integer; var icy: PChar; Len, Progress: DWORD; begin Result := 0; BASS_StreamFree(chan); progress := 0; SendMessage(win, WM_INFO_UPDATE, 0, 0); chan := BASS_StreamCreateURL(url, 0, BASS_STREAM_STATUS, @StatusProc, 0); if (chan = 0) then begin
SendMessage(win, WM_INFO_UPDATE, 1, 0); end else begin repeat len := BASS_StreamGetFilePosition(chan, BASS_FILEPOS_END); if (len = DW_Error) then break; progress := (BASS_StreamGetFilePosition(chan, BASS_FILEPOS_DOWNLOAD) - BASS_StreamGetFilePosition(chan, BASS_FILEPOS_CURRENT)) * 100 div len; SendMessage(win, WM_INFO_UPDATE, 2, progress); until progress >= 98;
icy := BASS_ChannelGetTags(chan, BASS_TAG_ICY); if (icy <> nil) then while (icy^ <> #0) do begin if (Copy(icy, 1, 9) = 'icy-name:') then SendMessage(win, WM_INFO_UPDATE, 3, DWORD(PChar(Copy(icy, 10, MaxInt))))
else if (Copy(icy, 1, 7) = 'icy-br:') then
SendMessage(win, WM_INFO_UPDATE, 4, DWORD(PChar('bitrate: ' + Copy(icy, 8, MaxInt)))); icy := icy + Length(icy) + 1; end; DoMeta(BASS_ChannelGetTags(chan, BASS_TAG_META)); BASS_ChannelSetSync(chan, BASS_SYNC_META, 0, @MetaSync, 0); BASS_ChannelPlay(chan, FALSE); end; cthread := 0; end;
procedure TfrmMain.WndProc(var Msg: TMessage); begin inherited; if Msg.Msg = WM_INFO_UPDATE then case msg.WParam of 0: begin Label1.Caption := 'connecting...'; Label2.Caption := ''; Label3.Caption := ''; Label5.Caption := ''; end; 1: begin Label1.Caption := 'not playing'; Error('Can''t play the stream'); end; 2: Label1.Caption := Format('buffering... %d%%', [msg.LParam]); 3: Label3.Caption := PChar(msg.LParam); 4: Label5.Caption := PChar(msg.LParam); 5: Label5.Caption := PChar(msg.LParam); 6: Label3.Caption := PChar(msg.LParam); 7: begin Label1.Caption := PChar(msg.LParam); Label2.Caption := '' ; end; 8: Label5.Caption := PChar(msg.LParam); end; end;
procedure TfrmMain.FormCreate(Sender: TObject); begin win := handle; if (HIWORD(BASS_GetVersion) <> BASSVERSION) then begin MessageBox(0, 'An incorrect version of BASS.DLL was loaded', nil, MB_ICONERROR); Halt; end; if (not BASS_Init(-1, 44100, 0, Handle, nil)) then begin Error('Can''t initialize device'); Halt; end; BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 0); BASS_SetConfig(BASS_CONFIG_NET_PROXY, 0); WaveStream:= TMemoryStream.Create; Id3v1Tag := TId3v1Tag.Create; boRec := False; tmrStart.Enabled := True; if not DirectoryExists('Files') then MkDir('Files'); end;
procedure TfrmMain.FormDestroy(Sender: TObject); begin BASS_Free; Id3v1Tag.Free; end;
procedure TfrmMain.StartRec; begin with WaveHdr do begin riff := 'RIFF'; len := 36; cWavFmt := 'WAVEfmt '; dwHdrLen := 16; wFormat := 1; wNumChannels := 2; dwSampleRate := 44100; wBlockAlign := 4; dwBytesPerSec := 176400; wBitsPerSample := 16; cData := 'data'; dwDataLen := 0; end; WaveStream.Write(WaveHdr, SizeOf(WAVHDR)); boRec := True; end;
procedure TfrmMain.StopRec; var i: integer; begin WaveStream.Position := 4; i := WaveStream.Size - 8; WaveStream.Write(i, 4); i := i - $24; WaveStream.Position := 40; WaveStream.Write(i, 4); WaveStream.Position := 0; Id3v1Tag.Artist := Label2.Caption; Id3v1Tag.Album := 'Top 100'; Id3v1Tag.Title := Label3.Caption; Id3v1Tag.year := '2007'; Id3v1Tag.genre := 'Pop'; id3v1Tag.comment := 'Recorded Shoutcast ' + DateTimeToStr(Now); Id3v1Tag.Track := Label1.Caption; Id3V1Tag.WriteToStream(WaveStream); WaveStream.SaveToFile('Files\' + Id3v1Tag.Track + ' - ' + Id3v1Tag.Artist + ' - ' + Id3v1Tag.Title + ' - ' + Id3v1Tag.Album + '.mp3'); end;
procedure TfrmMain.tmrStartTimer(Sender: TObject); var ThreadId: Cardinal; begin if (cthread = 0) then cthread := BeginThread(nil, 0, @OpenURL, PChar(urls[1]), 0, ThreadId); tmrStart.Enabled := False; end; |