1

I have installed Kodi on my Raspberry pi 2 with raspbian jessie. Media center works great it is just missing something, and that is games. I also installed RetroArch with some libraries, and I can run games running a bash script. What I would like to have is to run those commands directly from Kodi. For that I tried Advanced Launcher and ROM collection browser, but when script is run it runs the emulator, and I can hear the sound of the game, but the kodi does not go into the background. Can someone help how can I send Kody to background or kill the process so I can rung games, and then start kodi after exiting the game?

6
  • 1
    you can try sudo kill kodi - or if that fails sudo killall -9 kodi.bin to kill the process. Dec 12, 2015 at 14:50
  • sudo would be useless since kodi is running scripts as kodi user. Dec 12, 2015 at 15:05
  • so who are you logged in as? You say you are on Raspbian and running Kodi as a process, not a Kodi only system. The Pi user has full sudo access and so can by using sudo run the command as root and hence kill any running process- no matter who owns it. Dec 12, 2015 at 15:07
  • I am logged in as pi user, but the idea is to run the script from inside the kodi, to run the games. Dec 12, 2015 at 15:32
  • I do have the same problem: forum.kodi.tv/…
    – ricardo
    Nov 10, 2016 at 1:28

1 Answer 1

1

I found a way to do it.

I am using RaspBian and I do install retroPie on it to get retroarch running

I also have Advanced Launcher installed on Kodi

Follow the steps:

1 - Install retroPie on raspbian(or use retroPie distro)

2 - Install this packages with apt-get

sudo apt-get install at
sudo apt-get install kodi-eventclients-xbmc-send

3 - Edit the main.py from advanced launcher /home/pi/.kodi/addons/plugin.program.advanced.emulator.launcher/resources/main.py

add this:

arguments = arguments.replace('%categoryID%',    categoryID).replace('%CATEGORYID%',  categoryID)
arguments = arguments.replace('%launcherID%',    launcherID).replace('%lAUNCHERID%',  launcherID)
arguments = arguments.replace('%romID%',    romID).replace('%ROMID%',  romID)

after this:

arguments = arguments.replace('%romtitle%',    rom['m_name']).replace('%ROMTITLE%',  rom['m_name'])

4 - create this script on some directory ex:

/home/pi/adv_bian.sh

adv_bian.sh content:

#/bin/sh

log_file=/home/pi/advanced_launcher_script.log

rom=$2
emulator=$1
categoryID=$3
launcherID=$4
romID=$5


retro=/opt/retropie/emulators/retroarch/bin/retroarch
basecore=/opt/retropie/libretrocores/
baseconfig=/opt/retropie/configs/


# you need at command
# check for at command
if ! [ -x "$(command -v at)" ]; then
  echo 'Please install "at" with "sudo apt-get install at"' >> $log_file
  exit 1;
fi


# you need kodi-send installed
if ! [ -x "$(command -v kodi-send)" ]; then
  echo 'Please install "kodi-send" with "sudo apt-get install kodi-eventclients-xbmc-send"' >> $log_file
  exit 1;
fi


# configure each core here
if [ "$emulator" = "megadrive" ];
then
    core_emu=lr-picodrive/picodrive_libretro.so
elif [ "$emulator" = "snes" ];
then
    core_emu=lr-snes9x-next/snes9x2010_libretro.so
fi


retroconfig=$baseconfig$emulator/retroarch.cfg
core=$basecore$core_emu

# any unique name ( file must not exist )
helper_script=/home/pi/retro

if [ -f "$retroconfig" ] || [ -f "$core" ] ; then

    # send command to quit Kodi
    kodi-send --host=127.0.0.1 --port=9777 --action="Quit()"

cat <<EOT > $helper_script.run
    while pgrep "kodi" > /dev/null
    do
      echo "kodi is still running " >> $log_file
      sleep 2
    done
    sleep 1
    echo I will run retroarch now >>  $log_file
EOT

    echo $retro -L $core --config $retroconfig \"$rom\" --appendconfig /dev/shm/retroarch.cfg \&  >> $helper_script.run
    echo "$helper_script.running $categoryID $launcherID $romID | at now" >> $helper_script.run


cat <<EOT > $helper_script.running

echo cat $categoryID, launcher $launcherID, rom $romID >> $log_file

while pgrep "retroarch" > /dev/null
do
  echo "retroarch is running "  >> $log_file
  sleep 2
done

at -f /usr/bin/kodi now
sleep 5

kodi-send --host=127.0.0.1 --port=9777 --action="ActivateWindow(1,plugin://plugin.program.advanced.emulator.launcher/?catID=$categoryID&com=SHOW_ROMS&launID=$launcherID)"

EOT

    chmod +x $helper_script.run
    chmod +x $helper_script.running 
    at -f $helper_script.run now

else
    echo $retroconfig or $core not found >> $log_file
fi

Note In this script I just configure megadrive and snes, you need to add the configuration for the other cores.

5 - Now on Advanced Launcher's categories.xml file

5.1 configure the application tag like that:

<application>/home/pi/adv_bian.sh</application>

5.2 configure args tag like that:

<args>megadrive &quot;%rom%&quot; %categoryID% %launcherID% %romID% </args>

And you are done!

When You launch a rom it will Close Kodi and launch the rom

and when you close the rom, it will reopen Kodi in the same Category ex(mega drive) you leave it.

ps: english is not my primary language so if you find some english error on this guide, let me know. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.