Lena wrote: ↑Tue Nov 10, 2020 10:02 am
If there is no internet connection, I get error number 2 from BASS.
Error 2 is BASS_ERROR_FILEOPEN, but the documentation says that 32 (BASS_ERROR_NONET) should be reported if there is no Internet connection. Sounds like a bug in the BASS library.
Lena wrote: ↑Tue Nov 10, 2020 10:02 am
How to correctly insert this my new code internet connection into your Pascal code?
You already know how - handle the BASS_ERROR_NONET error. I would not treat BASS_ERROR_FILEOPEN as an Internet connection error. It could just be a wrong URL, or maybe the URL is temporarily offline because the server is down for maintenance at that moment, etc.
Since you are now handling multiple errors, I would suggest a slightly different approach:
Code: Select all
TThread.CreateAnonymousThread(
procedure
var
ercode: Integer;
ermsg: string;
begin
TThread.Queue(nil,
procedure
begin
AniIndicator1.Enabled := True;
AniIndicator1.Visible := True;
end
);
BASS_StreamFree(str);
str := BASS_StreamCreateURL(PChar('http://91.199.194.34:8000'), 0, BASS_UNICODE, nil, nil);
ercode := BASS_ErrorGetCode;
if ercode = BASS_OK then
begin
BASS_ChannelSetSync(str, BASS_SYNC_META, 0, @MetaSync, nil);
BASS_ChannelPlay(str, FALSE);
TThread.Queue(nil,
procedure
begin
AniIndicator1.Enabled := False;
AniIndicator1.Visible := false;
Viewport3D1.Visible := True;
FloatAnimation1.Enabled := True;
end
);
end else
begin
BASS_SampleFree (smp);
case ercode of
BASS_ERROR_TIMEOUT: ermsg := 'Sorry maintenance work on the music server.';
BASS_ERROR_FILEOPEN: ermsg := 'Sorry can't open the music file. Check the URL.';
BASS_ERROR_NONET: ermsg := 'No internet connection.';
// other error codes as needed..
else
ermsg := Format('Unable to create music stream. Error %d', [ercode]);
end;
TThread.Queue(nil,
procedure
AniIndicator1.Enabled := False;
AniIndicator1.Visible := false;
ShowMessage(ermsg);
end
);
end;
end
).Start;
Lena wrote: ↑Tue Nov 10, 2020 10:02 am
I spent the whole day but I cannot correctly insert my new code because I am confused in
if begin end
Pascal language is not very clear to me.
Really? 'begin ... end' is just Pascal's equivalent to C/C++'s '{}' curly braces.
Lena wrote: ↑Tue Nov 10, 2020 10:02 am
For example, I don't understand why your code works without a semicolon "
;":
That, on the other hand, can be tricky for Pascal beginners.
In Pascal, semicolon is a statement *separator*, not a statement *terminator*, like it is in C/C++. There is a difference. There are places in Pascal syntax where an explicit terminator is not needed, because the compiler knows there is a separation of statements, so the semicolon is optional in those places. Using a semicolon in those places just creates empty statements.
A semicolon is commonly used as a *terminator* in places it is not strictly needed, for consistency and portability between languages, and when beginners just don't know any better
Lena wrote: ↑Tue Nov 10, 2020 10:22 am
But I am not initializing anywhere
smp!
Well, then that is on you. You have a bug in your code that you need to fix. Stop trying to free something that you don't create. Or else create it properly.
Or, maybe you simply meant to call BASS_StreamFree(str) instead of BASS_SampleFree(smp)? That would make more sense, given the code you have shown so far. I haven't seen any code in your snippets that tries to free the HSTREAM returned by BASS_CreateStreamURL().
Lena wrote: ↑Tue Nov 10, 2020 10:22 am
Why does it work
BASS_SampleFree() fails if you give it an invalid handle. But you are not checking for that failure.
Lena wrote: ↑Tue Nov 10, 2020 10:22 am
how is it correct for HSAMPLE initializing?
I don't know. I don't use BASS. What are you trying to use the HSAMPLE for in the first place?