Reply To: start / stop kodi based on HDMI monitor status

Max2Play Home Forums Max2Play on Raspberry PI start / stop kodi based on HDMI monitor status Reply To: start / stop kodi based on HDMI monitor status

21. Januar 2016 at 16:48 #18045

Based on your code I wrote this (in perl) it works.

https://www.dropbox.com/s/fznkbe3xin6h5mk/kodi_hdmi.pl

#!/usr/bin/perl

$| = 1;
$debug = 1;

if ($debug == 0) { open(STDERR, ">/dev/null")}

# This will start kodi on startup if a device is on hdmi
# or will stop kodi processes if no device is on hdmi

$oldstat="X";    # force a change on startup

while(1) {

    $stat=<code>/opt/vc/bin/tvservice -n</code>;

    # if there is something plugged in and there was a change then Start KODI
    if (($stat ne "") && ($stat ne $oldstat)) {
        print "starting Kodi\n";
        #Turn on HDMI
        system("/opt/vc/bin/tvservice -p");
        #Turn on Kodi
        system("sudo -u pi -H -s /opt/max2play/start_xbmc.sh >> /dev/null 2>&1 &");
        $oldstat=$stat;
        next;
    }

    # if there is nothing plugged in and there was a change then Stop KODI
    if (($stat eq "") && ($stat ne $oldstat)) {
        print "stopping Kodi\n";
        #Turn off Kodi
        system("pkill -9 -f \"kodi.*standalone\"");
        #Turn off HDMI
        system("/opt/vc/bin/tvservice -o");
        $oldstat=$stat;
        next;
    }

sleep 10;

}