1

My mother has Alzehmiers and finds it hard on most days to switch the TV on and watch programs. I want to use a Raspberry Pi to stream movies to her TV as soon as she switches the TV on. I can attach a Raspberry Pi to the HDMI port and and have it running and playing videos.

What is the best way to do this or are there better alternatives as I just want her to switch the TV without doing anything else?

2
  • 1
    is the Pi always on, or is it powered by a USB port on the television? Aug 11 '18 at 3:36
  • It will always be on. Aug 13 '18 at 5:16
0

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:

Enable RC interface

Configure 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.

3
  • Thank you. This is the way I will go as it seems it will allow for power outages. You have given me a direction and code as well . As i am new to all of this it will take some time to work through this but thank you to all above Aug 13 '18 at 5:20
  • Thanks again to everyone for the suggestions. I have some limited programming experience but I should be able to wade through the above response from Greenonline. I have a raspberry pi and I will start playing. Aug 13 '18 at 5:31
  • You're welcome. Don't forget to upvote and accept any answers that you found to be useful Aug 13 '18 at 9:09
0

maybe you can clip together a bunch of tv shows together into a single video and have it just play on a loop with any video player. as long as the pi stays on you can turn the tv off and on and the pi will always be ready to go.

1
  • Yes this is a solution but I need to make sure that if the power goes off it reboots and loads up the stream Aug 13 '18 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.