Prevent screen turning off when watching video in XBMC

18,340

Solution 1

This seems to be a bug in the XBMC package for ubuntu

I'm not sure what version you have installed, but the version from the PPA* doesn't seem to have it on my system. This can be because I have different settings in ubuntu of course, so your milleage may vary.

If you don't, you can try to use XBMC as a session (on your login-screen, press the ubuntu logo next to your name and select XBMC. You won't get unity, but just fullscreen XMBC). The settings for unity will not be there, so you might luck out on not having a screensaver. (If you have auto-login set, you need to press logout to get the login screen)

* https://launchpad.net/~team-xbmc/+archive/ppa

Solution 2

We can create a shell script which would simulate mouse movement at a specified interval (only when XBMC is running) and prevent your screen from turning off.

Follow the steps:

  1. Install necessary tools:

    We would need xdotool Install xdotool to do this job for us. Install it by running the following command in terminal:

    sudo apt-get install xdotool
    
  2. The Script:

    Save the following script anywhere on your PC. You can modify sleep_period according to your needs, I have set it at 60 seconds. The script checks if there is a process called xbmc.bin running; and if it finds one, then it loops to simulate mouse movement while the process is active. Otherwise, checks for the process again after the specified interval.

    #!/usr/bin/env bash
    
    sleep_period=60s #seconds
    
    mouse_x=0
    mouse_y=0
    
    movement_px=2
      mouse_x=$(xdotool getmouselocation 2>/dev/null |  sed -e 's/x://' -e 's/y//' -e 's/ screen:.*$//' -e 's/ //' | awk 'BEGIN {FS=":"} {print $1}')
      mouse_y=$(xdotool getmouselocation 2>/dev/null |  sed -e 's/x://' -e 's/y//' -e 's/ screen:.*$//' -e 's/ //' | awk 'BEGIN {FS=":"} {print $1}')
    
    while true; do
      if [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; then
        while [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; do
          xdotool mousemove $((mouse_x+${movement_px})) $((mouse_y+${movement_px}))
          xdotool mousemove $((mouse_x-${movement_px})) $((mouse_y-${movement_px}))
          sleep ${sleep_period}
        done
      else
        sleep ${sleep_period}
      fi
    done
    
  3. Make this script executable:

    Right-click on the file you just saved >> Select Properties >> In the Permission tab, put the Check mark on Execute.

    make the script executable

  4. Execute this script automatically on every startup:

    We can do this with the help of Startup Applications. Open your Dash by pressing Enter and query for Startup Applications >> In Startup Applications Window, click on Add >> Then, in the dialog that pops up, fill the information:

    Name: optional, whatever you want to name this.

    Command: path to the file where you saved it.

    Comment: optional, if you wish to add some.

    startup applications preferences

  5. Restart your system and enjoy your movies with XBMC.


How to use it with other Applications

This was an example for XBMC (Process name xbmc.bin). However, it can also be used for any other process of your choice by just replacing xbmc.bin in the Script mentioned in Step-2 with the name of the process you wish. Find the following lines in the above script:

while true; do
  if [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; then
    while [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; do

And replace xbmc.bin in both lines 2 and 3 with the process name of your choice.


How to find the process name

  • With GUI (GNOME):

    We can use System Monitor to find the name of the process. Press Super to open Dash and query for "System Monitor" to launch it. In the Processes Tab, we can find the Process Name as the first column.

    System Monitor

  • With Terminal:

    We can run top to list all the running processes. The last column called Command gives us the name of the Process (however it is limited to first 15 characters).

    Terminal <code>top</code> command

Here we can see that Firefox is just named as firefox. So, if we want this behavior when Firefox is running; we would replace xbmc.bin in the script with firefox and everything else would work just fine.


Acknowledgement: I had found the script here. However, I have made necessary modifications to make it compact and satisfy the demands of the question.

Solution 3

A very simple solution is caffeine. Caffeine is a 'status bar application able to temporarily prevent the activation of both the screensaver and the "sleep" powersaving mode.'

Enabling it is as easy as clicking the status bar indicator, but you can also set it up such that it automatically disables the screensaver when you start xbmc. See the screenshot below

enter image description here

If you're using Gnome you can install the caffeine gnome extension. If not, for Ubuntu up to 15.04 (vivid) you can install caffeine from the launchpad ppa:

sudo add-apt-repository ppa:caffeine-developers/ppa
sudo apt-get update
sudo apt-get install caffeine

from 15.10 onwards you can install without ppa

sudo apt install caffeine

Enjoy!

Share:
18,340

Related videos on Youtube

thomasrutter
Author by

thomasrutter

Updated on September 18, 2022

Comments

  • thomasrutter
    thomasrutter over 1 year

    In 12.04, the screen never went to sleep while watching videos in XBMC. However after upgrading to 12.10 and changing no settings, it does.

    Is there any way I can prevent the screen automatically turning off while playing a video in XBMC, without actually disabling the screen from turning off at other times?

    Ideally, is there a XBMC specific setting for this? Was this a feature of XBMC that is now somehow broken in 12.10 or has this changed due to some other non-XBMC change within Ubuntu?

  • Aditya
    Aditya over 11 years
    @Nanne: No... Why would that be so; the shell script won't hog your system resources; and it wouldn't simulate mouse movement when XMBC is not running; as well as you won't have to remember to run this script everytime... Though a Preference setting in XMBC would obviously be the best solution; since I don't use XMBC - I don't know if such setting exists. I have tested this Shell script with Firefox and it works as expected by the OP.
  • Nanne
    Nanne over 11 years
    The problem is that the system shouldn't go to sleep while playing video (and for me it doesn't). This is clearly a workaround (you might call it a hack even) and I'm not saying it is bad, props to you for this great post, but still I would first look for a real solution (as you say, you do not know about XBMC, so there might be an actual one) before you try this. Again, nothing bad about your actual post, but don't you agree that making the mouse move is something you should try after "normal" settings fail?
  • Aditya
    Aditya over 11 years
    @Nanne As I said, a Preference Setting within XMBC to control it would obviously be the best solution. However, its prudent for me to expect that the OP has done his homework. Moreover, if such setting was available within XMBC, I think someone would have come up and posted his answer. The question being 7 days old as of now - I don't think its there in XMBC. Anyways, as you use XMBC, can you please check if it can be done :)
  • thomasrutter
    thomasrutter over 11 years
    Thanks for the bug link, that looks like the reason for my problem as I'm using the xbmc package from Ubuntu. I will try using XBMC as a session when I'm at home and see if that fixes it.
  • web.learner
    web.learner over 11 years
    I wouldn't call this a hack. People use shell scripts to do these things all the time. Awesome answer +1.
  • Sajesh Kumar
    Sajesh Kumar over 11 years
    Nice, but a bit complicated ;) You are probably better of using caffeine (the app, not the chemical component)
  • thomasrutter
    thomasrutter over 11 years
    This looks like a good tool.
  • thomasrutter
    thomasrutter over 11 years
    I'm using Gnome so I don't think I'm using xscreensaver. Thanks for your answer.
  • Sajesh Kumar
    Sajesh Kumar almost 8 years
    @PeterMortensen It does work, even on 16.04, that answer is outdated. Thanks for the headsup though, because my answer could use an update as well ;) I added the installation instructions for the newer Ubuntu versions.