3 error_log( "Using XMMS backend: ". $c->daemon_type
);
4 class xmms2Connection
{
5 var $active; // Once it actually is...
10 * Create a minimally initialised connection object
12 function xmms2Connection() {
13 $this->active
= false;
15 $this->status
= array();
19 * Connect to the remote xmms2
30 * Do a question/response pair with the daemon
32 function Daemon( $say ) {
33 if ( ! $this->active
) $this->Connect();
35 $command = 'xmms2 ' . $say;
38 exec( $command, &$output, &$retval );
44 * Query the xmms2 about it's current status
46 function UpdateStatus() {
47 $status = $this->Daemon( "info" );
48 foreach( $status AS $k => $v ) {
49 list( $key, $value ) = preg_split( '/ = /', $v, 2);
50 $this->status
[$key] = $value;
56 * Play a track. Xmms2 is OK if we tell it to play when it is already.
58 function Play( $track ) {
61 $this->UpdateStatus();
63 $this->Daemon("add $track");
64 $this->Daemon("play");
69 * Query the xmms2 about it's current playlist and position
71 function GetCurrent() {
74 $this->UpdateStatus();
75 $songnow = (object) array();
76 $songnow->started
= date( 'Y-m-d H:i:s', $this->status
['[server] laststarted'] );
77 $songnow->track
= str_replace( 'file://', '', $this->status
['[server] url'] );
82 * Query the xmms2 about it's current playlist and position
87 $this->UpdateStatus();
88 $next = $this->status
['song'] +
1;
89 $this->queue
= array();
94 $playlist = $this->Daemon( "list" );
95 foreach( $playlist AS $k => $v ) {
96 if ( substr( $v, 0, 2) == '->' ) $pos = 0;
99 $filename = preg_replace( '#^( |->)\[\d+/\d+\] #', '', $v );
100 $filename = preg_replace( '#^file://#', '', $filename );
101 $filename = urldecode( $filename );
102 $this->queue
[$pos++
] = $filename;
111 $GLOBALS["xmms2"] = new xmms2Connection();
117 /******************************************************************
118 * The actual API the web interface calls is then very simple...
119 ******************************************************************/
122 * Queue a file for playing
124 function daemon_play_track( $path ) {
126 error_log("adorno: DBG: Trying to play '$path'");
127 $xmms2->Play( $path );
132 * Get a list of the files currently queued for the future
134 function daemon_get_queue() {
136 $q = $xmms2->GetQueue();
142 * Get the currently playing track and it's starting time
144 function daemon_current_track() {
146 return $xmms2->GetCurrent();
151 * Get the currently playing track and it's starting time
153 function daemon_other_command( $action, $track ) {
157 $xmms2->Daemon('play');
160 $xmms2->Daemon($action);
163 $xmms2->Daemon($action);
166 error_log("adorno: ERROR: Unsupported command '$action'" );