Kodi Won't Stay Paused on Music Playback (Bluetooth issue?)


Hoping someone can help me. I’ve recently purchased a RPi3 as an “extension” to my existing RPi2 with OSMC/Kodi. I have a shared MySQL DB on the RPi2 which is also sharing out my music using SMB from an external HDD connect to the RPi2 via a powered USB hub.

The plan for the RPi3 is for it to be a “headless” setup using the Kodi Kore app to control and to playback music via my Echo Dot.

Using the guide on this site I managed to get Bluetooth support installed and working and I’m getting good results using the internal Bluetooth once I stopped using the internal WiFi adaptor and switched to using a wired connection.

The one issue I can’t sort out though is that if I am playing music and want to pause it after a short period of time, probably less than a minute, playback resumes. I’ve tried pausing using both the Kore app and also installed VNC server so I could access it remotely and tried pausing there but get the same behaviour both times. I also plugged in my IR receiver that I use on the RPi2 and paused using the remote to get a direct comparison to what happens on the RPi2, i.e. playback stays paused indefinitely.

The only real difference from my RPi2 which doesn’t have this issue is the Bluetooth connection and looking at the logs I can see the following from just after pressing pause so I’m assuming it’s related to Bluetooth:

EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<–
Error Type: <type ‘exceptions.AttributeError’>
Error Contents: ‘module’ object has no attribute ‘isBTPlayerActive’
Traceback (most recent call last):
File “/usr/share/kodi/addons/service.osmc.btplayer/service.py”, line 199, in onPlayBackPaused
if xbmc.isBTPlayerActive() and self.btPlayer.isPlaying() and self.btPlayer.player:
AttributeError: ‘module’ object has no attribute ‘isBTPlayerActive’
–>End of Python script error report<–

From what I’ve read streaming to a Bluetooth speaker is experimental but apart from this annoying pause issue it’s working perfectly for me. It wouldn’t be so bad if I could resume playback from where I left off in a song by stopping and restarting playback but unless I’ve missed something this is not possible.

Full debug log here: https://paste.osmc.tv/ewugoheweq

Any help or advice appreciated.

It’s probably best using the new bluez-alsa package instead of the older A2DP package which is deprecated


Thanks for the reply. Is there any guides/documentation available for moving from A2DP to bluez-alsa or is it just a case of uninstalling the old package and installing the new one?

You’d need to uninstall PulseAudio as well, but that should be it.

I think I need a little help. I’ve removed the old packages and compiled and installed bluez-alsa. I’ve got my Bluetooth speaker connected and can play a WAV file successfully using aplay from the command line but I get nothing when playing back a file in Kodi. Checked my audio output settings and they look ok so not sure where to go from here.

Any suggestions?

That’s one for @grahamh I believe.

After several false starts I’ve now managed to get audio playing back over my Bluetooth speaker. It got a bit hacky though as I’ve had to introduce a delay to the mediacenter service starting by disabling it from running automatically and then calling it from rc.local after my Bluetooth speaker has connected (also called from rc.local). If I allowed mediacenter to start automatically it won’t playback any music at all, tries for a few seconds and then just stops so it does appear it’s starting before some of the Bluetooth/ALSA services. I’ve also had to add ALSA:bluealsa to my advancedsettings.xml which works but then breaks if you access the audio settings from the GUI.

Unfortunately after all this I still have the original issue that music will not stayed paused and resumes playing. The original Bluetooth error I posted is no longer appearing in the logs but I can’t replicate the issue when setting it to play back over the RPi’s analogue connection so it does still seem to be Bluetooth related.

Is there any chance of making any progress with this do you think at this stage?

I can provide another log if it would be helpful but I actually had a better user experience using the original A2DP package (at least I found it a lot easier to get it working).

It looks like you have just installed bluez-alsa without the bits that go with it for it to work in OSMC. It needs a kodi patch and some .conf files (we don’t use the stock 20-bluealsa.conf). We are looking at automating the .conf file generation but still WIP.

Later today I’ll check if kodi has the right patches, install our package on a Pi3 and see if I can reproduce your issue. I haven’t tested on Pi for a while. Then I can send you instructions.

Thanks @grahamh, appreciate it

Progress report: I have our bluez-alsa package working on a Pi running Matrix, and can’t reproduce your issue.

But I tried it on a fresh install of Leia with less success (didn’t work at all). On a hunt for missing dependencies.

Try installing this, delete any alsa conf files you have made/edited first, sudo dpkg -i armv7-bluez-alsa-osmc.deb then follow the instructions in ~/.asoundrc.example (we use .asoundrc rather than advancedsettings.xml).

Since you had the a2dp package before I think it will just work. Your kodi may not be patched. If your HP/speaker doesn’t show up in kodi audio settings, restart kodi (Power->Exit) after connecting bluetooth for kodi to find it.

Thanks will give it a try. I did uninstall the A2DP package but will see how far I get (probably tomorrow). Could probably do with a fresh install as I’ve installed/uninstalled quite a few different packages but for starters will try what you suggest and go from there.

Thanks again

Just to be clear: I can’t get the package to work on a fresh install. You will likely have more success by not doing a fresh install until I can figure out what’s wrong. But do remove pulseaudio as a minimum.

Update: My fresh install is now working - not sure what happened. I’ve changed the link above to the latest version.

Just had chance to test this out on my existing installation.

Renamed my existing .asoundrc file, installed the package, re-enabled the mediacenter.service and took the startup of the service out of rc.local (but left my script to connect my Bluetooth device in there) , created a new .asoundrc file from the example with my Bluetooth devices details and finally removed the audio device settings from my advancedsettings.xml.

Rebooted and my Bluetooth device connects using my script and I can now see and select my Bluetooth speaker from the audio options page and all is good and persists after a reboot. So there’s definitely an improvement there.

Unfortunately I’m still left with the original issue of music not staying paused although I’ve now discovered that it doesn’t appear to be the fact that music won’t stay paused but that Kodi is receiving a “play” command and strangely while I was testing I stopped music playback but still had a song selected on the screen and after about a minute it started playing again from the start. I was monitoring kodi.log while this was happening with debugging turned on and saw the following just before it started playing:

2020-07-20 21:45:05.321 T:1894773472   DEBUG: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 50ms
2020-07-20 21:45:05.322 T:1420796640   DEBUG: Thread Timer start, auto delete: false
2020-07-20 21:45:05.332 T:1420796640   DEBUG: Thread Timer 1420796640 terminating
2020-07-20 21:45:05.350 T:1915495984   DEBUG: Keyboard: scancode: 0xc9, sym: 0x00b3, unicode: 0x0000, modifier: 0x0
2020-07-20 21:45:05.350 T:1915495984   DEBUG: Previous line repeats 1 times.
2020-07-20 21:45:05.351 T:1915495984   DEBUG: HandleKey: play_pause (0xf0bd) pressed, action is PlayPause

It still only seems to happen when playing back via my Bluetooth speaker, that “keypress” doesn’t happen if the output is set to Pi:Analogue but as soon as I set it back to my Bluetooth speaker the problem occurs.

I can provide a full log if required but hopefully this slightly new information may be helpful.

It occurred to me that I had only tested playing to a Bluetooth speaker using my Echo Dot and that I have a cheap CD player that can also receive Bluetooth and act as a speaker.

I repeated my tests using this device and low and behold the issue with receiving the play/pause command disappears. So it appears it’s not a Bluetooth issue so much as an Echo Dot issue.

At this point I’m guessing but as the Echo Dot can be an Audio Source or Audio Sink it has the ability to send data back the other way but my CD player is only an Audio Sink so can only receive. So could the Echo Dot be sending the play/pause back? Although why it would do this I don’t know. I was wondering if it’s possible to force the Echo Dot to only act as an Audio Sink maybe by using some settings in the .asoundrc file or maybe with a command within bluetoothctl although I’ve not found anything yet.

As always if anyone knows how I can stop the Echo Dot talking back (if that is indeed what is happening) then any advice is greatly received.

AFAIK a BT device can’t be a sink and a source at the same time unless it’s working as a hands-free or headset device (low audio quality). But commands to start/stop music can be sent from a BT speaker to the source. My JBL Flip pauses or restarts the music if I press the phone button for example.

I wonder if the Dot is just picking up some sound and sending play/pause.

BTW, shouldn’t be any need for your connect script. If the speaker is trusted, it will connect automatically.

Your last comment got me thinking (and Googling) and I hadn’t realised that the Echo Dot can actually use voice commands for basic Bluetooth functions (I was under the impression that you had a to have a skill to control at an app level so every day is a school day!)

So with music playing from Kodi to the Echo Dot I asked Alexa to pause… and it did and stayed paused for over an hour. I couldn’t get the music to resume or play via a voice command (resume tried to resume Spotify which was probably the last skill-based media I had played using the Echo dot and play said it was playing from Bluetooth but nothing actually happened) but when I pressed play on the Kore remote (just what I happened to be using to control Kodi at the time) the music continued from the point at which I had paused it.

Not sure this explains why the Echo Dot is resuming playback when the pause is initiated from Kodi but it does give me a workable solution that suits my needs.

I’ll test removing the Bluetooth connection script later on and then may try a fresh installation as I’m fairly certain I’ve got all sorts of bits and pieces installed from when I was messing around before.

Can I just check that with regards to a fresh install it should literally just be a case of starting from a fresh OSMC/Kodi installation and then installing the package above?

Also, is there a way of backing up the entire OS & Kodi so that if I can’t get it working again for any reason I can just put everything back as it was? I think I’m right in saying that the backup from My OSMC is just for Kodi?

Sure - you could take a block level backup of the bootable medium.

Ok, so fresh install done and the Bluetooth package installed (was missing some dependencies but worked fine once they were installed) and .asoundrc file created.

Bluetooth pairing, initial connection, play back all working perfectly.

Still got the issue where it won’t stay paused unless it’s done from a voice command (or the Alexa app on my phone I’ve also discovered) and the speaker won’t autoconnect on reboot so will have to put my script back in but other than that all good.

Thanks for all the help

Do you need a play_pause button for any other controller that shows up as a keyboard input? It might be a bit hacky but if you made a custom keymap with a noop action for that key it would stop it from doing anything. You could also tweak it to send either play OR pause so it becomes a single function control instead of a toggle. This will have no effect on anything using the JSON interface (like Kore).

Thanks for the suggestion. Now everything is pretty much working the plan is to control it using mainly Kore with VNC as backup or when I need a bit more access so that’s worth looking into/