-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrumMachine.py
More file actions
62 lines (42 loc) · 1.43 KB
/
Copy pathdrumMachine.py
File metadata and controls
62 lines (42 loc) · 1.43 KB
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
import flask , flask.views
import vlc
import time
import os
import random
from flask import request
import json
app = flask.Flask(__name__)
#https://www.youtube.com/watch?v=iSrZ6r7hwdM&list=PL0DA14EB3618A3507
# . venv/bin/activate
drumList = [];
@app.before_first_request
def _run_on_start():
for root, dirs, files in os.walk("./drums/",followlinks=False):
for file in files:
if file.endswith(('mp3','wav')):
drumList.append(os.path.join(root, file))
class View(flask.views.MethodView):
def get(self):
print "---------------------------------------------------"
playing = random.choice(drumList)
p = vlc.MediaPlayer(playing)
p.play()
print "playing sound: " + playing
return "<br>\n".join(drumList)
def put(self):
print "---------------------------------------------------"
parsed_json = json.loads(request.data)
if parsed_json['drum'] in drumList:
print "playing sound: " + parsed_json['drum']
p = vlc.MediaPlayer(parsed_json['drum'])
p.play()
return "playing sound: " + parsed_json['drum']
else:
print "sound not in list, try another"
return "sound not in list, try another"
app.add_url_rule('/',view_func=View.as_view('main'))
app.debug = True
app.run()
#app.run(host='0.0.0.0',port=12345)
#if __name__ == '__main__':
# app.run()