How to keep bluetooth headphones from turning off?

Ever since I've had my JBL-E50BT headphones I've been struggling to make them work properly on Ubuntu.

For instance every time I connect them, I have to switch the audio profile to HSP/HFP, disconnect, reconnect and switch back to A2DP before they will make any sound with A2DP. But it's something I can live with.

The JBL headphones have a "feature" that turns them off after no sound is played for n minutes, probably to preserve power. I'm not sure of the exact time, but it's something around 15-30 minutes.

Previously my Ubuntu system kept the headphones from idling, and a static noise could be heard from the headphones at any time it was connected. But ever since an update I did 2 weeks ago (not a dist upgrade) this does not seem to happen anymore. Right now, when sound is not playing, the system will stop outputting sound after 5 seconds and the headphones will go into idle-mode. No noise is then heard out of the headphones.

My question is: How do I prevent my headphones from going into idle-mode, answers to resolve issue with connecting the headphones would also be appreciated, as this will make reconnecting them after the timout a lot less annoying.

I am not concerned about the battery of the headphones, they can easily last a full work day playing music.

Update:

As suggested by @MadMike I tried the commands from this post.

$ pactl list cards short

0       alsa_card.pci-0000_00_03.0      module-alsa-card.c
1       alsa_card.pci-0000_00_1b.0      module-alsa-card.c
4       bluez_card.00_22_37_3F_C9_A4    module-bluez5-device.c

$ pactl set-card-profile 4 a2dp
Failure: No such entity

I'm not sure what to do with this result.


Solution 1:

I believe the issue with the above command, (pactl set-card-profile 4 a2dp), is that you do not have the correct profile name. Run pactl list cards. Then find your Bluetooth device. For example, mine is:
Card #3 Name: bluez_card.00_02_5B_01_3C_3B
Next find the Profiles: section. The profile I enable on my system is a2dp_sink. So my command to enable that profile is:
pactl set-card-profile 3 a2dp_sink

However, instead of the index number, I would recommend using the card name instead. The index number can change. If you run:
~$ pactl set-card-profile You have to specify a card name/index and a profile name
you get the above message. So, in my case, I would use:
pactl set-card-profile bluez_card.00_02_5B_01_3C_3B a2dp_sink