-
Notifications
You must be signed in to change notification settings - Fork 61
/
_player_engine.php
131 lines (101 loc) · 3.59 KB
/
_player_engine.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
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
<?php
/*
* PlayerUI Copyright (C) 2013 Andrea Coiutti & Simone De Gregori
* Tsunamp Team
* http://www.tsunamp.com
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RaspyFi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* UI-design/JS code by: Andrea Coiutti (aka ACX)
* PHP/JS code by: Simone De Gregori (aka Orion)
*
* file: player_engine.php
* version: 1.0
*
*/
include('inc/connection.php');
playerSession('open',$db,'','');
if (!$mpd) {
echo 'Error Connecting MPD Daemon';
} else {
// fetch MPD status
$status = _parseStatusResponse(MpdStatus($mpd));
// check for CMediaFix
if (isset($_SESSION['cmediafix']) && $_SESSION['cmediafix'] == 1) {
$_SESSION['lastbitdepth'] = $status['audio'];
}
// check for Ramplay
if (isset($_SESSION['ramplay']) && $_SESSION['ramplay'] == 1) {
// record "lastsongid" in PHP SESSION
$_SESSION['lastsongid'] = $status['songid'];
// Control for cancelling ramplay
// if (!rp_checkPLid($_SESSION['lastsongid'],$mpd)) {
// rp_deleteFile($_SESSION['lastsongid'],$mpd);
// }
// feth next song and put in SESSION
$_SESSION['nextsongid'] = $status['nextsongid'];
}
// register player STATE in SESSION
$_SESSION['state'] = $status['state'];
// Unlock SESSION file
session_write_close();
// ----- check and compare GUI state with Backend state ---- //
if ($_GET['state'] == $status['state']) {
// If the playback state is the same as specified in the ajax call
// Wait until the status changes and then return new status
$status = monitorMpdState($mpd);
}
// ----- check and compare GUI state with Backend state ---- //
$curTrack = getTrackInfo($mpd,$status['song']);
if (isset($curTrack[0]['Title'])) {
$status['currentartist'] = $curTrack[0]['Artist'];
$status['currentsong'] = $curTrack[0]['Title'];
$status['currentalbum'] = $curTrack[0]['Album'];
$status['fileext'] = parseFileStr($curTrack[0]['file'],'.');
} else {
$path = parseFileStr($curTrack[0]['file'],'/');
$status['fileext'] = parseFileStr($curTrack[0]['file'],'.');
$status['currentartist'] = "";
$status['currentsong'] = $song;
$status['currentalbum'] = "path: ".$path;
}
// CMediaFix
if (isset($_SESSION['cmediafix']) && $_SESSION['cmediafix'] == 1 && $status['state'] == 'play' ) {
$status['lastbitdepth'] = $_SESSION['lastbitdepth'];
if ($_SESSION['lastbitdepth'] != $status['audio']) {
sendMpdCommand($mpd,'cmediafix');
}
}
// Ramplay
if (isset($_SESSION['ramplay']) && $_SESSION['ramplay'] == 1) {
// set consume mode ON
// if ($status['consume'] == 0) {
// sendMpdCommand($mpd,'consume 1');
// $status['consume'] = 1;
// }
// Copy the text from /dev/shm
$path = rp_copyFile($status['nextsongid'],$mpd);
// Update MPD ramplay location
rp_updateFolder($mpd);
// Launch add/play song
rp_addPlay($path,$mpd,$status['playlistlength']);
}
// JSON response for GUI
header('Content-Type: application/json');
echo json_encode($status);
closeMpdSocket($mpd);
}
?>