Use VLC, with a long playlist, which starts automatically, when the Pi is powered up, using this solution, Autostart videostream without logging in.
As Jarmanda X suggests, power the Pi from the TV's USB (assuming that it has one), so that when the TV is powered on, the Pi starts as well.
Assuming that it would not be to confusing, as an added feature, you could get VLC to play random segments, of films in a playlist, in a random order using this Python solution, from SuperUser, Playback random section from multiple videos changing every 5 minutes, and refined in this thread, Play random section from random movies in VLC?.
import subprocess
import random
import time
import os
import sys
## Just seed if you want to get the same sequence after restarting the script
random.seed()
SocketLocation = "/Users/username/vlc.sock"
## You can enter a directory as a command line argument; otherwise it will use the default
if(len(sys.argv) >= 2):
MoviesDir = sys.argv[1]
else:
MoviesDir = "/Users/username/Movies"
## You can enter the interval in seconds as the second command line argument as well
if(len(sys.argv) >= 3):
IntervalInSeconds = int(sys.argv[2])
else:
IntervalInSeconds = 10
## Sends an arbitrary command to VLC
def RunVLCCommand(cmd):
p = subprocess.Popen("echo " + cmd + " | nc -U " + SocketLocation, shell = True, stdout = subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
print "returning: " + retval
return retval
## Clear the playlist
RunVLCCommand("clear")
RawMovieFiles = os.listdir(MoviesDir)
MovieFiles = []
FileLengths = []
## Loop through the directory listing and all subfolders adding each movie file found to the playlist
for root, dirs, files in os.walk(MoviesDir, topdown=False):
for name in files:
MovieFile = os.path.join(root, name)
if(MovieFile.lower().endswith(".mp4") or MovieFile.lower().endswith(".mkv") or MovieFile.lower().endswith(".avi") or MovieFile.lower().endswith(".ts") or MovieFile.lower().endswith(".vob") or MovieFile.lower().endswith(".mpg") or MovieFile.lower().endswith(".flv")):
MovieFiles.append(MovieFile)
RunVLCCommand("add \"" + MovieFile + "\"")
PlayListItemNum = 0
## Loop forever
while 1==1:
## Choose a random movie from the playlist
PlayListItemNum = random.randint(1, len(MovieFiles))
RunVLCCommand("goto " + str(PlayListItemNum))
FileLength = "notadigit"
tries = 0
## Sometimes get_length doesn't work right away so retry 50 times
while tries < 50 and FileLength .strip().isdigit() == False or FileLength.strip() == "0":
tries+=1
FileLength = RunVLCCommand("get_length")
## If get_length fails 50 times in a row, just choose another movie
if tries < 50:
## Choose a random duration between 20s and 45s
IntervalInSeconds = random.randint(20,45)
## Choose a random start time
StartTimeCode = random.randint(30, int(FileLength) - IntervalInSeconds);
RunVLCCommand("seek " + str(StartTimeCode))
## Turn on fullscreen
RunVLCCommand("f on")
## Wait until the interval expires
time.sleep(IntervalInSeconds)
## Skip to the next movie after playing for the given random duration
RunVLCCommand("next")
tries = 0
## Wait until the video stops playing or 50 tries, whichever comes first
while tries < 50 and RunVLCCommand("is_playing").strip() == "1":
time.sleep(1)
tries+=1
This was written for a Mac, so you would probably need to change /Users
to /home
in order to get it to work on the Pi correctly.
You have to set up a sock in order to programatically control VLC, which is described here: Controlling VLC via RC (“Remote Control”) interface using a UNIX domain socket (and no programming).
Enable RC interface:
Configure RC interface:
You would need to change the /Users
to the path that you use in the script for SocketLocation
.
I have consolidated all of the steps and links in a blog, Random VLC random clip player. Again, this blog is for OSX, but as they are both Unix it is a simple matter of changing the necessary paths.
You could modify the script so that it doesn't play random segments, only the playlist in a random order, so that every time the TV is switched on it doesn't always start with the same sequence of movies.
Also, for the autostart up, either ensuring the vlc
is in your PATH
environment variable (use echo $PATH
to verify), or using the full path to vlc
in the startup script.