So, after reading some manuals and doing some test, this is what I have now in my "MediaPause" routine:
// Reset counter
i := 1;
// Reset device list
lstADevices.Clear;
while BASS_GetDeviceInfo(i, ADeviceInfo) do
begin
lstADevices.Add(ADeviceInfo.name);
inc(i);
end;
intDevice := -1;
for i := 0 to lstADevices.Count - 1 do
begin
if lstADevices[i] = 'Bluetooth A2DP Stereo Audio (Bose AE2w 01.02.00( Stereo ))' then
begin
intDevice := i + 1; // + 1 is important, because the list starts with 0! (for BASS 0 means 'no device')
BASS_GetDeviceInfo(intDevice, ADeviceInfo);
intFlag := ADeviceInfo.flags;
if intFlag = 67108868 then
begin
for j := 0 to lstADevices.Count - 1 do
begin
if lstADevices[j] = 'Speakers (Realtek High Definition Audio)' then
begin
intDevice := j + 1; // The list starts at 0
break;
end;
end;
end;
break;
end;
end;
BASS_Init(intDevice, 44100, 0, Application.Handle, nil);
blnBASS := BASS_ChannelSetDevice(AudioStream, intDevice);
if not blnBASS then
intBASSErrorCode := BASS_ErrorGetCode;
BASS_ChannelPlay(AudioStream, False);
When the program is started and the bluetooth headset is not connected, it will not be enumerated to get into the device list. So I have to enumerate the devices at any necessary time. I wanted to implement this into the "tick counter" for displaying the time (ticks in seconds), but because of the following behavior I didn't do so yet.
I can switch (BASS_ChannelSetDevice) between the bluetooth headset and the speakers once. When I want/have to switch again, to whatever reason, I get the error code 4 which means BASS_ERROR_BUFLOST (The sample buffer was lost).
I tried to find anything according the buffer size, but couldn't find anything.
I check the flag value 67108868 of the bluetooth device, because I couldn't find any other way to check if the device is available or not.
If the bluetooth device has been connected once during the runtime, it will always get enumerated even it is disconnected afterwards. It also has the "enabled" state, so I only found the difference in the flag value.
Packing the above code into the tick counter for the display I could get it managed to change the devices from speakers to headset automatically, which would be the "perfect" way for me, but due to the problem with the "buffer lost" error, I removed it from the tick counter routine.
Like Victoria and Arioch 'The mentioned, I paused the player before changing the device. Like mentioned, it works one time and the next time I run into the "buffer lost" error. This means, there is no error produced, but the output isn't changed then.
As I'm not sure if "my way" is correct in any sense, is there a "more safe" way to change the devices?
MPage