Hello. I want to make my Pi send a “CECActivateSource” command whenever the Pi begins playback of a video. The peripheral settings for CEC do not have this option (only switch when booting up, and switch when deactivating the screensaver). Activating source when the screensaver goes away is not getting the job done when I push a video using Yatse on my phone.
Some Google searching informed me that this is possible using a Python script so when “xbmc.Player().isPlayingVideo()” it sends an “xbmc.executebuiltin(‘CECActivateSource’)” command. . Simple enough, right?
The problem is I have no idea how Python scripts work, what extension I should give the script’s file, or where should I put it once it is written.
Would somebody with the technical know-how be kind enough to help me out?
Edit:
Further googling suggests a script that goes something like:
Edit: Solved.
Just name this baby “autoexec.py” and place it at /home/.kodi/userdata
Works like a charm. CEC turns on my TV and switches to the correct input when I push a video to Kodi through my phone.
import xbmc,xbmcgui
class Player(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
def onPlayBackStarted(self):
xbmc.executebuiltin('CECActivateSource()')
player = Player()
mon = xbmc.Monitor()
while(not mon.waitForAbort(10)):
pass
Yep! The only downside is that my TV is kinda old and it can take up to 10 secs from powering up to switching input, and that’s 10 secs of video I missed. Aside from that, it works like a charm!
I noticed that when I copy&paste the code from the forum to notepad the spaces are wrong… and Python is very picky about counting spaces. So instead of copy/pasting that code try downloading it from here: Dropbox - autoexec.py - Simplify your life
Then put it at /home/.kodi/userdata and reboot.
One last thought: Perhaps the python scripts request module addon is necessary? I already had it, because it is a requirement for iStream to work. You can find it in the official Kodi repo, or DL it directly from their page: http://addons.kodi.tv/show/script.module.requests/
If it still doesn’t work after all of this, then I have no idea what I did right… I just know I got it working!
I already had it because another add-on pre-installed it, as above mentioned. I’m not certain if you need it or not for this… but if you still can’t get it to work, give that a try.