-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontrol.php
76 lines (65 loc) · 1.77 KB
/
control.php
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
<?php
require_once('lib/global.php');
$action = $_GET['action'];
switch ($action) {
case 'stop':
$mympd->Stop();
break;
case 'play':
$mympd->Play();
break;
case 'pause':
$mympd->Pause();
break;
case 'playpause':
if ($mympd->state == MPD_STATE_PLAYING) {
$mympd->Pause();
}
else {
$mympd->Play();
}
break;
case 'prev':
$mympd->Previous();
break;
case 'next':
$mympd->Next();
break;
case 'repeat':
// toggle repeat
$repeat = ($mympd->repeat == 0 ? 1 : 0);
$mympd->SetRepeat($repeat);
break;
case 'volume':
$volume = $_GET['value'];
$mympd->SetVolume($volume);
die();
break;
}
echo mpd_info();
function mpd_info() {
global $mympd, $_CONFIG;
// we will create an array of info detailing the current state of MPD
// and return it as JSON.
$info = array();
$info['state'] = $mympd->state;
$current_track = $mympd->playlist[$mympd->current_track_id];
$cover_link = $_CONFIG['music_directory'] . '/'
. substr($current_track['file'], 0, strrpos($current_track['file'], '/') + 1)
. var_filter($current_track, $_CONFIG['album_cover_name']);
if (file_exists($cover_link)) {
$info['coverimage'] = 'lib/image.php?file=' . $cover_link . '&size=' . $_CONFIG['album_cover_size'];
}
$info['title'] = $current_track['Title'];
$info['album'] = $current_track['Album'];
$info['artist'] = $current_track['Artist'];
$info['file'] = $current_track['file'];
$info['filename'] = substr($current_track['file'], strrpos($current_track['file'], '/') + 1);
$info['length'] = $mympd->current_track_length;
$info['position'] = $mympd->current_track_position;
$info['volume'] = $mympd->volume;
$info['repeat'] = $mympd->repeat;
$info['random'] = $mympd->random;
return json_encode($info);
}
?>