Recently I wanted to play a video as my screensaver. Thinking this would be a simple job, I set about searching. After a little time I could not find anything about using gnome-screensaver to play videos. But this has been done with xscreensaver, so I set about lifting the solution to gnome-screensaver.
What follows was adapted from the electric sheep project to use MPlayer to render the screensaver. Two files need to be created, one .desktop that is used by the gnome-screensaver and the other is a script to select a video launch MPlayer.
Step 1)
Its a good idea to test mplayer on a video file,Code:sudo apt-get install mplayer
just to make sure it can render well enough. If there are problems it could be the case that a different video driver is required, specified with the -vo command line argument. See MPlayer doc for more info.Code:mplayer yourvideo.file
Step 2)
Create a new file in /usr/share/applications/screensavers/ called movie.desktop,
Then as root enter into movie.desktopCode:sudo touch /usr/share/applications/screensavers/movie.desktop
This will be used by gnome-screensaver and specifies that the script movie.sh should be run when the screensaver is launched.Code:[Desktop Entry] Encoding=UTF-8 Name=Movie Comment=Plays Videos TryExec=movie.sh Exec=movie.sh StartupNotify=false Terminal=false Type=Application Categories=Screensaver; OnlyShowIn=GNOME;
Step 3) - movie.sh
There are a few choice that can be made, the script I now present has a list of video files and randomly chooses one, plays it then randomly selects another and continues. It should be fairly simple to modify to suit your own purposes.
Create the script,
make it executableCode:sudo touch /usr/lib/gnome-screensaver/gnome-screensaver/movie.sh
enter the followingCode:sudo chmod 755 /usr/lib/gnome-screensaver/gnome-screensaver/movie.sh
NOTE: See bootch's comment below for a better way of writing this script.
Please be careful when copying the code that "#! /bin/bash" is at the beginning of the file (no white space).Code:#! /bin/bash ## setup MPlayer aruments, remove -nosound if you want the video ## to play sound. If you have to specify the video driver to use ## then add that to the list MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet" ## add videos to this list, one will be chosen and played, note ## that wild cards can be used here VIDEOS=( "/path/to/vid.avi" /path/with/wildcard/*avi) ## child pid, no need to modify CPID=0 ## we handle SIGTERM and SIGINT here to kill the child ## if active then quit. function ex { if [ $CPID -gt 0 ] then kill -s 9 $CPID fi exit 0 } trap ex SIGINT SIGTERM ## loop while video list is not empty while [ ${#VIDEOS[*]} -gt 0 ] do ## pick a random video VIDEO=${VIDEOS["$RANDOM % ${#VIDEOS[*]}"]} ## play video mplayer $MPLAYERARGS "$VIDEO" & CPID=$! ## wait for video to finish wait $CPID ## if things went wrong then exit if [ $? -ne 0 ] then exit 1 fi CPID=0 done
This script might look complicated, but most of the code is taken up with killing mplayer when the script is killed. This could have been simplified by the use of exec but then to get a different video the screensaver has to be restarted. In a great simplification of the above script would have only one video, which would loop. See
Step 4)Code:#! /bin/bash ## setup MPlayer aruments, remove -nosound if you want the video ## to play sound. If you have to specify the video driver to use ## then add that to the list MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet" ## path to video VIDEO=/path/to/vid exec mplayer $MPLAYERARGS -loop 0 "$VIDEO"
Configure the script by entering videos into the list VIDEOS, to understand the syntax of the list see bash arrays (http://tldp.org/LDP/abs/html/arrays.html). Make sure that quotes are not used around paths with wild cards as this stops shell expansion.
Finally go System -> Preferences -> Screensaver and select Movie from the list. Your movie should start playing in the preview window, if not make sure the above steps were followed.
All Done.
To test the script remove "-wid $XSCREENSAVER_WINDOW" and "-really-quiet" from the arguments, and run the script from a terminal to see error messages.



Adv Reply



Bookmarks