-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTVSim.py
83 lines (68 loc) · 1.78 KB
/
TVSim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Raspberry Pi TV simulator - Python code
# by Rodrigo Feliciano - https://www.youtube.com/pakequis
#
# This code play a random video from a directory and wait for
# "channel" change.
#
import vlc # Python-VLC library
import time
import os
import random
import RPi.GPIO as GPIO
# start execution
print ("start")
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(3, GPIO.OUT)
GPIO.output(3, GPIO.LOW)
random.seed()
#list all files in a directory and subdirectories
def list_files(dir):
r = []
for root, dirs, files in os.walk(dir):
for name in files:
r.append(os.path.join(root, name))
return r
#movies path
path = "/home/test/RaspTV/movies"
file = random.choice(list_files(path))
print(file)
time.sleep(1)
Instance = vlc.Instance()
player = Instance.media_player_new()
player.toggle_fullscreen()
media = Instance.media_new(file)
player.set_media(media)
player.play()
time.sleep(2)
while not player.is_playing():
time.sleep(0.001)
GPIO.output(3, GPIO.HIGH) # Change Arduino to video_on state
flag = 0
#loop
while True:
if(GPIO.input(12) == GPIO.LOW):
flag = 1
else:
if (flag == 1):
print("change")
flag = 0
player.stop
time.sleep(0.1)
file = random.choice(list_files(path))
media = Instance.media_new(file)
player.set_media(media)
player.play()
time.sleep(2)
# Next video if video is finished
if not (player.is_playing()):
print('next')
player.stop
time.sleep(0.1)
file = random.choice(list_files(path))
media = Instance.media_new(file)
player.set_media(media)
player.play()
time.sleep(2)
# end of execution
print ("stop")