Quanta droppings.
[adorno.git] / inc / adornoPlayer.php
blob4fd4fd77da990b621d38bfd47bf3b75a8ce18d27
1 <?php
3 error_log( "Using Adorno backend: ". $c->daemon_type );
4 function daemon_play_track( $path ) {
5 $fifo = fopen( "/var/run/adorno/fifo", "w" );
6 fputs( $fifo, "queue $path\n" );
7 fclose($fifo);
9 return true;
12 function daemon_current_track() {
13 $result = (object) array();
15 if ( ! file_exists( "/var/run/adorno/queue.txt" ) ) return $result;
17 $fd = fopen( "/var/run/adorno/queue.txt", "r" );
18 if ( $fd ) {
19 $track = fgets( $fd, 300 );
20 $track = trim( $track, "\n" );
21 $started = fgets( $fd, 300 );
22 $started = trim( $started, "\n" );
23 fclose($fd);
25 $result->track = $track;
26 $result->started = $started;
29 return $result;
32 function daemon_get_queue() {
33 if ( ! file_exists( "/var/run/adorno/queue.txt" ) ) return array();
34 $fd = fopen( "/var/run/adorno/queue.txt", "r" );
35 if ( $fd ) {
36 $track = fgets( $fd, 2048 ); // Skip the "now playing" - it showed at the top.
37 $track = fgets( $fd, 300 ); // Skip the start time...
39 $tracks = array();
40 while( !feof( $fd ) ) {
41 $tracks[] = fgets( $fd, 2048 ); // Yes: we assume all tracks are less than 2048 bytes.
43 fclose($fd);
45 return $tracks;
48 function daemon_other_command( $action, $track ) {
49 $fifo = fopen( "/var/run/adorno/fifo", "w" );
50 if ( ! ereg( "^(/music)|(http://)", "$track" ) ) {
51 $track = "/music" . "$track";
53 # $track = eregi_replace( " ", "\\ ", $track);
54 fputs( $fifo, "$action $track\n" );
55 fclose($fifo);