How do I stop xscreensaver during movies play?
Solution 1
You may try similar script to this one. Watch for player state through DBUS.
I lower delay to 55 sec, work better with 1min screen saver idle time.
-
Example VLC:
BTW, VLC in Ubuntu 14.04 has DBUS interface enabled by default. Where in Ubuntu 12.04 is not. Check it from:
Tools → Preferences → Advanced (or All) → Interface → Control Interfaces → D-Bus control interface. (Apply then Restart VLC)
-
Create a file
heartbeat.sh
in~/Desktop/
:#!/bin/bash while sleep 55 do if [ "$(pgrep vlc)" != "" ] then state=$(bash -c 'gdbus call --session \ --dest org.mpris.MediaPlayer2.vlc \ --object-path /org/mpris/MediaPlayer2 \ --method org.freedesktop.DBus.Properties.Get \ "org.mpris.MediaPlayer2.Player" \ "PlaybackStatus"') if [ "$state" = "(<'Playing'>,)" ] then #xscreensaver-command -deactivate xset s reset fi fi done
Open terminal Ctrl+Alt+t
-
Add run permissions:
chmod +x ~/Desktop/heartbeat.sh
-
Run script:
~/Desktop/heartbeat.sh
Try VLC player.
-
-
For Gnome MPlayer (D-Bus enabled by default), use:
"$(pgrep gnome-mplayer)"
and--dest org.mpris.MediaPlayer2.gnome-mplayer
-
For (Totem) Videos player (D-Bus plugin disabled by default),
Edit → Plugins → Check D-Bus service. (Restart totem)
Use:
"$(pgrep totem)"
and--dest org.mpris.MediaPlayer2.totem
-
This is modified with to work with any player that provide MPRIS. It gets the list dynamically (drawback, it doesn't distinguish between audio only play and video play). The best way I think is to put manually the list of players you like:
#!/bin/bash players_list=$(gdbus call --session --dest org.freedesktop.DBus \ --object-path / --method org.freedesktop.DBus.ListNames | \ awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }') while sleep 55 do for player in $players_list do state=$(gdbus call --session \ --dest $player \ --object-path /org/mpris/MediaPlayer2 \ --method org.freedesktop.DBus.Properties.Get \ "org.mpris.MediaPlayer2.Player" \ "PlaybackStatus") if [ "$state" = "(<'Playing'>,)" ] then echo $player $state send signal #xscreensaver-command -deactivate #use xset to work with all screensaver tools and avoid dimming display ... xset s reset break else echo $player $state fi done done
Debug hints:
-
Watch X idle time
watch -n1 xprintidle
or:
while sleep 1; do xprintidle; done;
-
Check if disabling screensaver works (while running this script, xscreensave should not pop up)
#!/bin/bash while sleep 55 do #xscreensaver-command -deactivate #xdg-screensaver reset xset s reset done
-
Check for DBUS list for MPRIS player interface, example with VLC running:
gdbus call --session --dest org.freedesktop.DBus \ --object-path / --method org.freedesktop.DBus.ListNames | \ awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }'
Output:
org.mpris.MediaPlayer2.vlc org.mpris.MediaPlayer2.vlc.instance3939
Or using
dbus-send
commanddbus-send --session \ --dest=org.freedesktop.DBus \ --type=method_call \ --print-reply \ /org/freedesktop/DBus \ org.freedesktop.DBus.ListNames \ | grep org.mpris.MediaPlayer2.
Output:
string "org.mpris.MediaPlayer2.vlc" string "org.mpris.MediaPlayer2.vlc.instance3939"
References:
- How to set up DBus query to get play state of VLC? original script by JB0x2D1
- MPRIS D-Bus Interface Specification
- Use
qdbusviewer
to check the correct destination name or to use other player you like.
Solution 2
For MPV, and mplayer, the heartbeat functionality is built in.
1) Locate your mpv configuration file. locate mpv.conf
2) Open it up. sudo nano /path/to/mpv.conf
3) Add this line at the bottom. heartbeat-cmd="/usr/bin/xscreensaver-command -deactivate > /dev/null"
4) Close, and save. Ctrl+X if using nano.
Find out where to find your mpv.conf file here (configuration is identical on Arch Linux), https://wiki.archlinux.org/index.php/Mpv#Configuration
If the environment variable XDG_CONFIG_HOME is not set, user configuration files will be read from the ~/.config/mpv directory. System-wide configuration files are read from the /etc/mpv directory.
Solution 3
I noticed all the answers here seemed unnecessarily complex; you don't really need to do this based on a specific media player - all you need to do is detect if any audio is playing. I'm actually surprised this isn't a feature built into xscreensaver. Here's a super simple bash script:
#!/bin/bash
while true
do
state=$(pacmd list-sinks | grep -A 4 "*" | grep "state: " | cut -c 9-)
if [[ $state == SUSPENDED || $state == IDLE ]]
then
echo "State: $state. Not pausing screensaver."
sleep 2m
else
echo "State: $state. Pausing screensaver."
xscreensaver-command -deactivate > /dev/null
sleep 4m
fi
done
Related videos on Youtube
Chris26284
Updated on September 18, 2022Comments
-
Chris26284 over 1 year
I'm running Ubuntu 12.04. I installed xscreensaver in place of gnome.screensaver.
My problem is that I cannot get the screensaver to stop popping up when I'm watching a movie on Movie Player. I have Movie Player set to disable screensavers but it's not working on xscreensaver.
How do I change the program files to disable xscreensaver while Movie Player is running?
-
joe about 10 yearsThe XScreenSaver page has this to say about it.
-
Chris26284 about 10 yearsThank you for that. Unfortunately MPlayer doesn't work and I can't find MPV.
-
Chris26284 about 10 yearsThank you again. I'll definitely look into MPV and PPAs.
-
Evan Carroll about 6 yearsThis question should be closed and deleted as it doesn't even specify a program. It's like asking "How do I shutdown my computer" without specifying an operating system.
-
-
user.dz about 10 years@Chris26284, I have updated answer. I confirmed, it works in 12.04 as I tested it in a VirtualBox. So did you get any error on terminal when you run the script?
-
Chris26284 about 10 yearsThis still doesn't work at all. I've tried both ways. I've deleted previous attempts and tried again from scratch. This does nothing.
-
user.dz about 10 years@Chris26284, I feel difficult to debug or to expect the cause. Only if you have patient to do so. I will try to add some debugging hints
-
Chris26284 almost 10 yearsI recently updated my system to Ubuntu 14.04? Should the above fix work any better now?
-
klaar about 2 yearsDoes this work for video that's not played fullscreen though?
-
klaar about 2 yearsDoes this exclude audio-only playback like Spotify? Because only video should prevent the screensaver to engage, not pure audio.
-
Alter Lagos about 2 years@klaar no idea TBH and it has been a while since I used Ubuntu so I don't have a way to try it now. Anyway, try the script and you tell us if works :)