5 error_log( "Using XMMS backend: ". $c->daemon_type
);
6 class xmms2Connection
{
7 var $active; // Once it actually is...
12 * Create a minimally initialised connection object
14 function xmms2Connection() {
15 $this->active
= false;
17 $this->status
= array();
21 * Connect to the remote xmms2
32 * Do a question/response pair with the daemon
34 function Daemon( $say ) {
35 if ( ! $this->active
) $this->Connect();
37 $command = 'xmms2 ' . $say;
40 exec( $command, &$output, &$retval );
46 * Query the xmms2 about it's current status
48 function UpdateStatus() {
49 $status = $this->Daemon( "info" );
50 foreach( $status AS $k => $v ) {
51 list( $key, $value ) = preg_split( '/ = /', $v, 2);
52 $this->status
[$key] = $value;
54 $status = $this->Daemon( "state" );
55 $this->status
['state'] = $status[0];
60 * Play a track. Xmms2 is OK if we tell it to play when it is already.
62 function Play( $track ) {
65 $this->UpdateStatus();
67 $this->Daemon("add $track");
68 if ( $this->status
['state'] == 'Stopped' ) {
69 $this->Daemon("next");
70 $this->Daemon("play");
73 $this->Daemon("play");
78 * Query the xmms2 about it's current playlist and position
80 function GetCurrent() {
83 $this->UpdateStatus();
84 $songnow = (object) array();
85 $songnow->started
= date( 'Y-m-d H:i:s', $this->status
['[server] laststarted'] );
86 $songnow->track
= str_replace( 'file://', '', $this->status
['[server] url'] );
92 * Query the xmms2 about it's current playlist and position
97 $this->UpdateStatus();
98 $next = $this->status
['song'] +
1;
99 $this->queue
= array();
104 $playlist = $this->Daemon( "list" );
105 foreach( $playlist AS $k => $v ) {
108 $filename = preg_replace( '#^( |->)\[\d+/\d+\] #', '', $v );
109 if ( substr($filename,0,7) == 'file://' ) {
110 $filename = substr( $filename, 7 );
111 $filename = urldecode( $filename );
112 $this->queue
[$pos++
] = $filename;
115 else if ( $pos < 0 && substr( $v, 0, 2) == '->' ) {
125 $GLOBALS["xmms2"] = new xmms2Connection();
131 /******************************************************************
132 * The actual API the web interface calls is then very simple...
133 ******************************************************************/
136 * Queue a file for playing
138 function daemon_play_track( $path ) {
140 error_log("adorno: DBG: Trying to play '$path'");
141 $xmms2->Play( $path );
146 * Get a list of the files currently queued for the future
148 function daemon_get_queue() {
150 $q = $xmms2->GetQueue();
156 * Get the currently playing track and it's starting time
158 function daemon_current_track() {
160 return $xmms2->GetCurrent();
165 * Get the currently playing track and it's starting time
167 function daemon_other_command( $action, $track ) {
171 $xmms2->Daemon('play');
174 $xmms2->Daemon($action);
177 $xmms2->Daemon($action);
180 error_log("adorno: ERROR: Unsupported command '$action'" );