If the music is playing the connection is fine (it doesn't turn off for no reason). The problem comes when I pick a new song from my files, as soon as I push start to play it, it drops the connection. It also drops the connection if I stop and start the play during a song. Then trying to manually reconnect by opening bluetooth settings and switching it on, it will reconnect once or maybe twice, but after that, it cuts out and multiple attempts to manually switch it on are useless.
It seems as though touchpad input to control what songs are playing, and in particular, stopping and starting it, are the trigger for disconnection.
I tried editing the /etc/bluetooth/main.conf file, so that the ReconnectAttempts=7 was not commented out. The AutoEnable=true was already on.
Then I saw that various people had repeated problems that they had difficulty solving and someone recommended installing Pipewire instead of using the default Pulseaudio, saying it solved their problem. I did that, thoroughly following instructions here:
https://linuxconfig.org/how-to-install-pipewire-on-ubuntu-linux
to disable Pulseaudio and to cause pipewire to run automatically, but the connection continues to behave the same way. Turning the speaker off and on again, or restarting the computer has no effect.
I went into bluetoothctl, listed the device name and trusted it.
This did not change anything.
It seems like there might be other things in the bluetooth/main.conf file that might be able to be changed, but I can't find any more in depth explanation of how it works, other than the comments in the file itself.