forked from JuliusCode/MP4MUSEUM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp4museum-playthis.py
257 lines (227 loc) · 6.51 KB
/
mp4museum-playthis.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/python
# mp4museum.org by julius schmiedel
# playthis version
#
# all files looped, GPIO triggered playback
#
# http://mp4museum.org/mp4museum-v4.20.img.zip
# take a v4 image and replace its python script with this
# does not work with v5 or newer!
#
# files must be located in /playthis directory
# files must be named 1.mp4, 2.mp4 etc
# all files and the directory must be in lowercase
#
# supports only one stick
# (or at least insert playthis stick first)
import os
import sys
import glob
from subprocess import Popen, PIPE
import RPi.GPIO as GPIO
FNULL = open(os.devnull, "w")
playthis = 0
# setup GPIO pin
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(11, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(12, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(15, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(19, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
# functions to be called by event listener
def playN1(channel):
global playthis
if ( playthis == 1 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 1
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN2(channel):
global playthis
if ( playthis == 2 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 2
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN3(channel):
global playthis
if ( playthis == 3 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 3
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN4(channel):
global playthis
if ( playthis == 4 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 4
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN5(channel):
global playthis
if ( playthis == 5 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 5
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN6(channel):
global playthis
if ( playthis == 6 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 6
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN7(channel):
global playthis
if ( playthis == 7 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 7
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN8(channel):
global playthis
if ( playthis == 8 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 8
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN9(channel):
global playthis
if ( playthis == 9 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 9
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
def playN10(channel):
global playthis
if ( playthis == 10 ):
playthis = 0
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
else:
playthis = 10
poll = player.poll()
if ( poll == None ):
player.stdin.write("q")
# add event listener
GPIO.add_event_detect(7, GPIO.FALLING, callback=playN1, bouncetime=1234)
GPIO.add_event_detect(11, GPIO.FALLING, callback=playN2, bouncetime=1234)
GPIO.add_event_detect(12, GPIO.FALLING, callback=playN3, bouncetime=1234)
GPIO.add_event_detect(13, GPIO.FALLING, callback=playN4, bouncetime=1234)
GPIO.add_event_detect(15, GPIO.FALLING, callback=playN5, bouncetime=1234)
GPIO.add_event_detect(16, GPIO.FALLING, callback=playN6, bouncetime=1234)
GPIO.add_event_detect(18, GPIO.FALLING, callback=playN7, bouncetime=1234)
GPIO.add_event_detect(19, GPIO.FALLING, callback=playN8, bouncetime=1234)
GPIO.add_event_detect(21, GPIO.FALLING, callback=playN9, bouncetime=1234)
GPIO.add_event_detect(22, GPIO.FALLING, callback=playN10, bouncetime=1234)
# please do not remove my logo screen
player = Popen(['omxplayer', '--adev', 'both', '/home/pi/mp4museum.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
# the loop
while(1):
for files in sorted(glob.glob(r'/media/*/*.mp4')):
if ( playthis == 1 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/1.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 1 ):
playthis = 0
if ( playthis == 2 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/2.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 2 ):
playthis = 0
if ( playthis == 3 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/3.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 3 ):
playthis = 0
if ( playthis == 4 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/4.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 4 ):
playthis = 0
if ( playthis == 5 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/5.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 5 ):
playthis = 0
if ( playthis == 6 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/6.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 6 ):
playthis = 0
if ( playthis == 7 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/7.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 7 ):
playthis = 0
if ( playthis == 8 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/8.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 8 ):
playthis = 0
if ( playthis == 9 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/9.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 9 ):
playthis = 0
if ( playthis == 10 ):
player = Popen(['omxplayer','--adev', 'both','/media/usb/playthis/10.mp4'],stdin=PIPE,stdout=FNULL)
player.wait()
if ( playthis == 10 ):
playthis = 0
# etc.
if ( playthis == 0 ):
player = Popen(['omxplayer','--adev', 'both',files],stdin=PIPE,stdout=FNULL)
player.wait()