-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpvtest.py
executable file
·66 lines (49 loc) · 1.56 KB
/
mpvtest.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
#!/usr/bin/env python3
import mpv
import signal
import time
from datetime import datetime
def now():
currentDateAndTime = datetime.now()
return currentDateAndTime.strftime("%Y%m%d%H%M%S")
def make_observer(player_name):
def observer(_prop_name, prop_val):
# print(f'{player_name}: {prop_val}')
try:
title = prop_val['icy-title']
print( now() + " " + title )
except:
pass
return observer
# using alsa + dmixer + equalizer
# see .asoundrc
# set mpv options to use the *mixing* alsa channel
# https://medium.com/intrasonics/robust-continuous-audio-recording-c1948895bb49
# https://wiki.ubuntuusers.de/mpv/
options= {
'audio_device' : 'alsa/plugmixequal',
'volume_max' : '1000.0',
'keep_open' : 'no',
'idle' : 'yes',
'gapless_audio' : 'yes',
'audio_buffer' : '0.2',
'stream_lavf_o' : 'reconnect_streamed=1,reconnect_delay_max=300',
'network_timeout' : '60',
'cache-secs' : '2'
}
# define a first player
player = mpv.MPV( **options )
player.observe_property('metadata', make_observer('player'))
# define a second player
player2 = mpv.MPV( **options )
# Play a stream from the internet (SomaFm Groove Salad)
player.volume=60.0
# player.play('http://somafm.com/seventies.pls')
player.play('http://ice1.somafm.com/groovesalad-128-mp3')
time.sleep(5)
# Play a sound file from the local filesystem
player2.volume=60.0
player2.play('/home/pi/sounds/beep.wav')
# print("start recording")
# player.stream_record="/tmp/audio.mp3"
signal.pause()