Heckie75 / kodi-addon-pasink

Kodi addon in order to set Pulse-Audio sinks with bluez and combined-sink support
MIT License
13 stars 1 forks source link

Error using addon - not sure why... help. #1

Closed neocogent closed 5 years ago

neocogent commented 5 years ago

I've been trying your addon to help get bluetooth devices on my Kodi install. Plugin seemed to load ok after setting ownership to kodi user. On System, Settings, Add-ons the plugin shows up in Music Add-ons and seems to discover A2DP sinks as the two I have are listed there. But when trying to select a sink via Music, Add-ons, Pulseaudio Sink Setter I get an error and indication to check log file. Log file contains apparently related following info:

WARNING: RunScript called for a non-script addon 'plugin.audio.pasink'. This behaviour is deprecated.
13:05:39.242 T:140708648294144  NOTICE: ES: Client  from ::ffff:192.168.4.20 timed out
13:05:47.747 T:140709028689664   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.KeyError'>
                                            Error Contents: ('sink',)
                                            Traceback (most recent call last):
                                              File "/var/lib/kodi/.kodi/addons/plugin.audio.pasink/addon.py", line 513, in <module>
                                                browse(path)
                                              File "/var/lib/kodi/.kodi/addons/plugin.audio.pasink/addon.py", line 422, in browse
                                                build_dir_structure()
                                              File "/var/lib/kodi/.kodi/addons/plugin.audio.pasink/addon.py", line 259, in build_dir_structure
                                                if default_sink["sink"] != bluez["sink"]:
                                            KeyError: ('sink',)
                                            -->End of Python script error report<--
13:05:47.760 T:140710366718336   ERROR: GetDirectory - Error getting plugin://plugin.audio.pasink/
13:05:47.760 T:140710366718336   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.audio.pasink/) failed

My system is Asus Celeron motherboard running Mint 18.2 (Ubuntu based) and Kodi 17.6 Git 20171114-a9a7a20.

Please help if possible. Thx.

Heckie75 commented 5 years ago

Hi,

in case that you have installed the plugin from the zip archive, that was provided in Github, please download the latest zip file that I have updated yet.

After you have updated the plugin in Kodi, please open the plugin settings and press the buttons for discover sinks (alsa and a2dp). Then save settings.

Then try to open music addon again. Please let me know if this error still appears.

If yes, please attach also your settings file, which you find here: $HOME/.kodi/userdata/addon_data/plugin.audio.pasink/settings.xml

It would also be intesting what happens when you execute this script on command line: $HOME/.kodi/addons/plugin.audio.pasink/lib/pasink -ll

It should list something like this:

$ $HOME/.kodi/addons/plugin.audio.pasink/lib/pasink -ll

Default sink:
0       S       module-alsa-card.c      Aureon Dual USB Digital Stereo (IEC958) alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00.iec958-stereo  100%

Plugged Alsa card devices:
0       S       module-alsa-card.c      Aureon Dual USB Digital Stereo (IEC958) alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00.iec958-stereo  100%
1       S       module-alsa-card.c      Internes Audio Digital Stereo (HDMI)    alsa_output.pci-0000_00_1b.0.hdmi-stereo        100%

Sinked Bluetooth A2DP device:

Paired Bluetooth A2DP devices:
00:02:3C:26:24:D9       paired  Creative T12 Wireless

Best regards

neocogent commented 5 years ago

Thank you for your response. I am using git clone and then unzipping the zip file. The link you provide in the git readme doesn't download correctly as it seems to only get some html not the actual zip (for me anyway using Firefox on linux).

I did a git pull and saw a new zip which I unzipped to kodi/addons. Then I restarted kodi and did the discovery for both in the addon configure. Two bluetooth items show up and both look correct but only one is currently powered on. After that I dumped the settings.xml and then tried to use the plugin from the Music section. It gave me an error again suggesting to check the log. A quick check shows similar messages as before.

The settings.xml your requested is below (before trying to open addon but after discovery).

EDIT - Just realized below is from resources directory as no settings.xml in plugin.audio.pasink exists.

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <category label="ALSA aliases">
    <setting visible="eq(4,)" label="Discover devices" type="lsep" />
    <setting label="No devices here. Run discover first!" type="text" visible="eq(3,)" enable="false" />
    <setting label="Start discovery" type="action" action="RunScript($ID,discover)" default="" />

    <setting label="ALSA Sink 1" type="lsep" visible="!eq(1,)" />
    <setting label="Sink" type="text" id="alsa_id_0" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="alsa_name_0" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="alsa_alias_0" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="alsa_hide_0" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="ALSA Sink 2" type="lsep" visible="!eq(1,)" />
    <setting label="Sink" type="text" id="alsa_id_1" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="alsa_name_1" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="alsa_alias_1" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="alsa_hide_1" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="ALSA Sink 3" type="lsep" visible="!eq(1,)" />
    <setting label="Sink" type="text" id="alsa_id_2" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="alsa_name_2" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="alsa_alias_2" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="alsa_hide_2" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="ALSA Sink 4" type="lsep" visible="!eq(1,)" />
    <setting label="Sink" type="text" id="alsa_id_3" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="alsa_name_3" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="alsa_alias_3" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="alsa_hide_3" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="ALSA Sink 5" type="lsep" visible="!eq(1,)" />
    <setting label="Sink" type="text" id="alsa_id_4" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="alsa_name_4" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="alsa_alias_4" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="alsa_hide_3" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />
  </category>
  <category label="A2DP aliases">
    <setting visible="eq(4,)" label="Discover devices" type="lsep" />
    <setting label="No devices here. Run discover first!" type="text" visible="eq(3,)" enable="false" />
    <setting label="Start discovery" type="action" action="RunScript($ID,discover)" default="" />

    <setting label="Bluetooth Audio 1" type="lsep" visible="!eq(1,)" />
    <setting label="MAC" type="text" id="a2dp_id_0" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="a2dp_name_0" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="a2dp_alias_0" enable="!eq(-2,)" visible="!eq(-2,)" default="" />  
    <setting label="Hide sink" type="bool" id="a2dp_hide_0" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="Bluetooth Audio 2" type="lsep" visible="!eq(1,)" />
    <setting label="MAC" type="text" id="a2dp_id_1" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="a2dp_name_1" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="a2dp_alias_1" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="a2dp_hide_1" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="Bluetooth Audio 3" type="lsep" visible="!eq(1,)" />
    <setting label="MAC" type="text" id="a2dp_id_2" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="a2dp_name_2" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="a2dp_alias_2" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="a2dp_hide_2" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="Bluetooth Audio 4" type="lsep" visible="!eq(1,)" />
    <setting label="MAC" type="text" id="a2dp_id_3" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="a2dp_name_3" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="a2dp_alias_3" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="a2dp_hide_3" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />

    <setting label="Bluetooth Audio 5" type="lsep" visible="!eq(1,)" />
    <setting label="MAC" type="text" id="a2dp_id_4" enable="false" visible="!eq(0,)" default="" />
    <setting label="Name" type="text" id="a2dp_name_4" enable="false" visible="!eq(-1,)" default="" />
    <setting label="Alias" type="text" id="a2dp_alias_4" enable="!eq(-2,)" visible="!eq(-2,)" default="" />
    <setting label="Hide sink" type="bool" id="a2dp_hide_4" enable="!eq(-3,)" visible="!eq(-3,)" default="false" />
  </category>
</settings>

Note that the setting above seems to indicate discovery has not been run but I definitely selected Start Discovery for both audio types. Nothing happened for ALSA and A2DP had already two items and no change after clicking discovery. I guess that isn't actually updating the settings but no error msg was shown.

I should note that in my previous attempt the bluetooth adapter was connected manually (using bluetoothctl commands) and I could play music via ffplay at command line. This time I could not get a successful connect at command line and even though status is paired I could not play music. This has been a hit/miss thing for me with bluetoothctl. Apparently randomly it will or won't connect and I have not found the reason for that (despite speakers being on, paired and ready).

Thanks for any further suggestions you may have.

EDIT I tried a bit more poking round and running pasink in lib direcetory manually. pasink -l lists two paired devices. pasink 'Bose Mini II SoundLink' starts a sequence of disconnect/connect but connect reports as fail, so it never gets added to sink list. I guess right now I need to resolve why sometimes bluetooth cannot connect and other times it does before re-trying the plugin usage.

EDIT Re-powered speakers and tried pasink again. This time after second connect attempt it did connect and added as sink. I went back to plugin configure in kodi and did discovery again. Now the A2DP Audio 1 device is shown as "sink". That may be one step better but the settings.xml file still does not exist in root plugin directory (only resources, assumed to be template used by addon).

I noticed in error msg it notes KeyError for "sink" when in actual xml file it is "Sink". Not sure if that case difference may be problem but would presume that would have been detected long ago if the case. Just noticing. Anyway now have connected (sinked) speaker device.

Heckie75 commented 5 years ago

Hi again,

you wrote

EDIT - Just realized below is from resources directory as no settings.xml in plugin.audio.pasink exists.

The settings.xml from resources directory $HOME/.kodi/addons/plugin.audio.pasink/resources is just the virgin template. It will never change. If there is no settings-xml file in $HOME/.kodi/userdata/addon_data/plugin.audio.pasink we have a problem. Please check permissons of the folder for instance by doing as folows:

$ ls -l $HOME/.kodi/userdata
total 84
drwxr-xr-x 26 heckie heckie  4096 Sep 24 21:27 addon_data

Here you can see that the user heckie, who runs Kodi, is able to write in folder addon_data which is located in $HOME/.kodi/userdata

If this is not the case you must grant access, e.g. by executing this :

find $HOME/.kodi/userdata -type d -exec chmod 777 {} \;

# grant full permissions to all folders located in Kodi's userdata folder.

You can also check who runs Kodi by doing this:

$ ps -ef | grep kodi.bin | grep -v grep
heckie    2266  2263 10 Sep28 ?        01:15:19 /usr/lib/x86_64-linux-gnu/kodi/kodi.bin

The first column says that kodi has been started by user heckie

Further you wrote:

I tried a bit more poking round and running pasink in lib direcetory manually. pasink -l lists two paired devices. pasink 'Bose Mini II SoundLink' starts a sequence of disconnect/connect but connect reports as fail,

To be honest the pasink script, which is also written by me, is a little bit fragile. The script connects to a bluetooth device and waits a few seconds before it checks if pulse audio has setup a new audio sink automatically. Sometimes pulse audio doesn't create the new sink altought the bluetooth device is connected. In this case the pasink script disconnects the bluetooth device and reconnects it and so on. I haven't found the reason yet, why pulse audio sometimes doesn't setup the sink. Maybe you want to double-check the file /etc/pulse/default.pa which must be edited with root permission. It must contain the following setting:

load-module module-switch-on-connect

Best regards

Heckie75 commented 5 years ago

... I have uploaded a new version which should be more robust in case that pasink hasn't found a default sink for audio.

neocogent commented 5 years ago

Oops. I see now I was looking in wrong place. Found the correct addon_data folder and got settings.xml as shown below (after doing config - discovery step):

<settings>
    <setting id="a2dp_alias_0" value="" />
    <setting id="a2dp_alias_1" value="" />
    <setting id="a2dp_alias_2" value="" />
    <setting id="a2dp_alias_3" value="" />
    <setting id="a2dp_alias_4" value="" />
    <setting id="a2dp_hide_0" value="false" />
    <setting id="a2dp_hide_1" value="false" />
    <setting id="a2dp_hide_2" value="false" />
    <setting id="a2dp_hide_3" value="false" />
    <setting id="a2dp_hide_4" value="false" />
    <setting id="a2dp_id_0" value="00:1B:66:81:93:CE" />
    <setting id="a2dp_id_1" value="04:52:C7:21:4F:46" />
    <setting id="a2dp_id_2" value="" />
    <setting id="a2dp_id_3" value="" />
    <setting id="a2dp_id_4" value="" />
    <setting id="a2dp_name_0" value="MOMENTUM M2 AEBT" />
    <setting id="a2dp_name_1" value="Bose Mini II SoundLink" />
    <setting id="a2dp_name_2" value="" />
    <setting id="a2dp_name_3" value="" />
    <setting id="a2dp_name_4" value="" />
    <setting id="alsa_alias_0" value="" />
    <setting id="alsa_alias_1" value="" />
    <setting id="alsa_alias_2" value="" />
    <setting id="alsa_alias_3" value="" />
    <setting id="alsa_alias_4" value="" />
    <setting id="alsa_hide_0" value="false" />
    <setting id="alsa_hide_1" value="false" />
    <setting id="alsa_hide_2" value="false" />
    <setting id="alsa_hide_3" value="false" />
    <setting id="alsa_id_0" value="" />
    <setting id="alsa_id_1" value="" />
    <setting id="alsa_id_2" value="" />
    <setting id="alsa_id_3" value="" />
    <setting id="alsa_id_4" value="" />
    <setting id="alsa_name_0" value="" />
    <setting id="alsa_name_1" value="" />
    <setting id="alsa_name_2" value="" />
    <setting id="alsa_name_3" value="" />
    <setting id="alsa_name_4" value="" />
</settings>

I didn't retry yet as dinner time here. Just thought I'd post this in case there is some clue there. Permissions seem to be correct for running as user "kodi".

Heckie75 commented 5 years ago

Ok, I guess that my fix helps since it prevents to fail in case that there are no default sinks, e.g. a soundcard. After I have seen that you seem to have bluetooth devices only and therefore no hard-wired soundcard this is likely the case. Please retry with the updated code.

Enjoy your dinner! I'm going to have breakfast ;-)