Author Topic: NetRadio  (Read 287 times)

Serhii

  • Guest
NetRadio
« on: 25 Oct '22 - 17:17 »
Good afternoon
I ask for the help of experts. Wrote a program in Lazarus to play Stream radio streams.
The program compiles, but the response is silence.

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Bass;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    ListBox1: TListBox;
    Stop: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StopClick(Sender: TObject);

  end;

var
  Form1: TForm1;


implementation


 var
  url_radio: HSTREAM;
{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  BASS_Init(-1,44100,0,Handle,nil);
  BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1);
  BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 0);

end;


procedure TForm1.StopClick(Sender: TObject);
begin
  BASS_ChannelStop(url_radio);
  BASS_StreamFree(url_radio);
  url_radio:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    url:string;
begin
  try
  url:=Edit1.Text;
  BASS_StreamFree(url_radio);
  BASS_ChannelSetAttribute(url_radio, BASS_ATTRIB_VOL, 100);
  BASS_StreamCreateURL(PChar(url), 0, BASS_STREAM_BLOCK or BASS_STREAM_STATUS or BASS_STREAM_AUTOFREE, nil, nil);
  BASS_ChannelPlay(url_radio,False);
  except
    on e:Exception do
   end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if not BASS_ChannelPause(url_radio) then BASS_ChannelPlay(url_radio,false);
end;


end.
                   

Ian @ un4seen

  • Administrator
  • Posts: 24792
Re: NetRadio
« Reply #1 on: 25 Oct '22 - 18:01 »
Please check the return values of the BASS function calls to find out if any are failing. If any are failing, you can then use BASS_ErrorGetCode to find out why.

Serhii

  • Posts: 6
Re: NetRadio
« Reply #2 on: 25 Oct '22 - 18:09 »
How to check?

Serhii

  • Posts: 6
Re: NetRadio
« Reply #3 on: 25 Oct '22 - 18:31 »
An error has been found:
BASS_ChannelPlay(url_radio,False); BASS_ERROR_HANDLE       = 5;    // invalid handle 
What to change?

Chris

  • Posts: 2104
Re: NetRadio
« Reply #4 on: 25 Oct '22 - 22:04 »
Hi should to be
Code: [Select]
url_radio := BASS_StreamCreateURL(PChar(url), 0, BASS_STREAM_BLOCK or BASS_STREAM_STATUS or BASS_STREAM_AUTOFREEor BASS_UNICODE, nil, nil);

Serhii

  • Posts: 6
Re: NetRadio
« Reply #5 on: 26 Oct '22 - 08:30 »
Don't work

Falcosoft

  • Posts: 123
Re: NetRadio
« Reply #6 on: 26 Oct '22 - 08:55 »
Hi should to be
Code: [Select]
url_radio := BASS_StreamCreateURL(PChar(url), 0, BASS_STREAM_BLOCK or BASS_STREAM_STATUS or BASS_STREAM_AUTOFREEor BASS_UNICODE, nil, nil);

Contrary to Delphi Lazarus/FreePascal uses UTF-8 encoding for unicode strings by default and not UTF-16. So PChar in Lazarus works only with ansi or UTF-8 strings but not with UTF-16. So when using the  BASS_UNICODE flag you should convert your UTF-8 string explicitly to UTF-16 and use PWideChar instead of PChar.
Something like this:
...
Code: [Select]
var Tmp: UnicodeString;
Tmp := url;   

url_radio := BASS_StreamCreateURL(PWideChar(Tmp), 0, BASS_STREAM_BLOCK or BASS_STREAM_STATUS or BASS_STREAM_AUTOFREE or BASS_UNICODE, nil, nil);

Serhii

  • Posts: 6
Re: NetRadio
« Reply #7 on: 27 Oct '22 - 07:03 »
It worked, thanks

Serhii

  • Posts: 6
Re: NetRadio
« Reply #8 on: 27 Oct '22 - 07:22 »
Good afternoon
I'm trying to compile under WinCe InetRadio, an error pops up: "bass.pas(732,1) Fatal: Syntax error, "identifier" expected but "FUNCTION" found". Error: function BASS_SetConfig(option, value: DWORD): BOOL; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF}; external bassdll;
Everything works under win32.

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Buttons, Bass;

type

  { TForm1 }

  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn10: TBitBtn;
    BitBtn11: TBitBtn;
    BitBtn12: TBitBtn;
    BitBtn13: TBitBtn;
    BitBtn14: TBitBtn;
    BitBtn15: TBitBtn;
    BitBtn16: TBitBtn;
    BitBtn17: TBitBtn;
    BitBtn18: TBitBtn;
    BitBtn19: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn20: TBitBtn;
    BitBtn21: TBitBtn;
    BitBtn22: TBitBtn;
    BitBtn23: TBitBtn;
    BitBtn24: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    Button2: TButton;
    Button3: TButton;
    Fallout: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Stop: TButton;
    procedure BitBtn10Click(Sender: TObject);
    procedure BitBtn11Click(Sender: TObject);
    procedure BitBtn12Click(Sender: TObject);
    procedure BitBtn13Click(Sender: TObject);
    procedure BitBtn14Click(Sender: TObject);
    procedure BitBtn15Click(Sender: TObject);
    procedure BitBtn16Click(Sender: TObject);
    procedure BitBtn17Click(Sender: TObject);
    procedure BitBtn18Click(Sender: TObject);
    procedure BitBtn19Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn20Click(Sender: TObject);
    procedure BitBtn21Click(Sender: TObject);
    procedure BitBtn22Click(Sender: TObject);
    procedure BitBtn23Click(Sender: TObject);
    procedure BitBtn24Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure BitBtn9Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StopClick(Sender: TObject);

  end;

var
  Form1: TForm1;


implementation


 var
  url_radio: HSTREAM;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  BASS_CONFIG_DEV_BUFFER();
  BASS_Init(-1,44100,0,Handle,nil);
  BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1);
  BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 0);

end;



procedure TForm1.StopClick(Sender: TObject);
begin
  BASS_ChannelStop(url_radio);
  BASS_StreamFree(url_radio);
  url_radio:=0;
end;



procedure TForm1.BitBtn10Click(Sender: TObject);
var
    url1:string;
begin
  try
  url1:='http://listen.42fm.ru:8000/stealkill-128';
  BASS_StreamFree(url_radio);
  BASS_ChannelSetAttribute(url_radio, BASS_ATTRIB_VOL, 100);
  url_radio := BASS_StreamCreateURL(PChar(url1), 0, BASS_STREAM_BLOCK or BASS_STREAM_STATUS or BASS_STREAM_AUTOFREE, nil, nil);
  BASS_ChannelPlay(url_radio,False);

  except
    on e:Exception do
   end;

end;

Tell me what's the problem?