Einzelnen Beitrag anzeigen

Nogge

Registriert seit: 15. Jul 2004
336 Beiträge
 
Delphi 7 Professional
 
#5

Re: func BeginThread: "Canvas does not allow drawing&am

  Alt 26. Mär 2005, 18:08
Ich habe diese Variante aus einem Beispiel für die Verwendung der BASS-Engine:
Delphi-Quellcode:
const
  urls: array[0..9] of String = (
    'http://64.236.34.196/stream/2001','http://205.188.234.129:8024',
    'http://64.236.34.97/stream/1006','http://206.98.167.99:8406',
    'http://160.79.1.141:8000/','http://206.98.167.99:8006',
    'http://205.188.234.4:8016','http://205.188.234.4:8014',
    'http://server2.somafm.com:8000','http://server1.somafm.com:8082'
  );

function OpenURL(url: PChar): Integer;
var
  icy: PChar;
begin
  Result := 0;
  BASS_StreamFree(Form1.chan); // close old stream
  Form1.Label4.Caption := 'connecting...';
  Form1.Label3.Caption := '';
  Form1.Label5.Caption := '';
  Form1.chan := BASS_StreamCreateURL(url, 0, BASS_STREAM_META or BASS_STREAM_STATUS,
                                                            @StatusProc, 0);
  if (Form1.chan = 0) then
  begin
    Form1.Label4.Caption := 'not playing';
    Error('Can''t play the stream');
  end
  else
  begin
    // get the broadcast name and bitrate
    icy := BASS_StreamGetTags(Form1.chan, BASS_TAG_ICY);
    if (icy <> nil) then
      while (icy^ <> #0) do
      begin
        if (Copy(icy, 1, 9) = 'icy-name:') then
          Form1.Label4.Caption := Copy(icy, 11, Length(icy) - 10)
        else if (Copy(icy, 1, 7) = 'icy-br:') then
          Form1.Label5.Caption := 'bitrate: ' + Copy(icy, 9, Length(icy) - 8);
        icy := icy + Length(icy) + 1;
      end;
    // get the stream title and set sync for subsequent titles
    DoMeta(BASS_StreamGetTags(Form1.chan,BASS_TAG_META));
    BASS_ChannelSetSync(Form1.chan,BASS_SYNC_META,0,@MetaSync,0);
    // play it!
    BASS_ChannelPlay(Form1.chan,FALSE);
  end;
  Form1.cthread := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ThreadId: Cardinal;
begin
  if (cthread <> 0) then
    MessageBeep(0)
  else
    cthread := BeginThread(nil, 0, @OpenURL, PChar(urls[TButton(Sender).Tag]), 0, ThreadId);
end;
Was ist denn bei diesem Code anders als bei meinem (mit diesem funktioniert es nämlich einwandfrei!)?
  Mit Zitat antworten Zitat