3 include_once('AwlQuery.php');
5 switch ( $c->daemon_type
) {
6 case 'mpd': include("mpdPlayer.php"); break;
7 case 'vlc': include("vlcPlayer.php"); break;
8 case 'xmms2': include("xmms2Player.php"); break;
9 default: include("adornoPlayer.php");
13 * High level function to play a track
15 function PlayTrack( $path, $hash ) {
16 if ( isset($_GET['act']) && $_GET['act'] == 'no' && ( !isset($_POST['act']) ||
$_POST['act'] == 'no') ) {
17 error_log( sprintf("DBG: PlayTrack: *NOT* Queueing '%s' for playing", $path) );
21 error_log( sprintf("DBG: PlayTrack: Queueing '%s' for playing", $path) );
23 if ( daemon_play_track($path) ) {
24 $qry = new AwlQuery( "SELECT track_played(?) ", $hash );
25 $qry->Exec("PlayTrack");
31 * High level function to get the current track as a database object
33 function current_track() {
35 $current_track = daemon_current_track();
37 $query = "SELECT *, extract( EPOCH FROM duration)::int AS secs ";
38 if ( preg_match( '/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}/', $current_track->started
) ) {
39 $query .= ", extract( EPOCH FROM ('".$current_track->started
."'::timestamp + duration))::int AS finishing ";
41 $query .= "FROM tracks WHERE path_name = ? ; ";
43 $qry = new AwlQuery( $query, $current_track->track
);
44 if ( $qry->Exec('current_track') && $qry->rows() > 0 ) {
45 $track = $qry->Fetch();
46 $track->state
= $current_track->state
;
54 * High level function to crudely display the current track
56 function show_queue() {
58 $queue = daemon_get_queue();
60 echo "<h3>Coming up...</h3>\n<p class=\"track_queue\">";
61 foreach( $queue AS $k => $v ) {
62 echo nice_track_name($v) . "<br>\n";
69 * High level function to return an array of $track objects
71 function current_queue() {
73 $queue = daemon_get_queue();
78 foreach( $queue AS $k => $track ) {
79 $param_id = ':t'.$position;
80 $in_list .= ($position++
== 0 ?
'' : ', ') . $param_id ;
81 $params[$param_id] = $track;
84 if ( $in_list == '' ) return $queue;
87 * Select the track information from the database
90 $sql = sprintf("SELECT *, EXTRACT( 'epoch' FROM duration ) AS dur_secs FROM tracks WHERE path_name IN ( %s );", $in_list );
91 // printf( "\n%s\n", $in_list );
93 $qry = new AwlQuery( $sql, $params );
94 if ( $qry->Exec("current_queue",__LINE__
,__FILE__
) && $qry->rows() ) {
95 while( $track = $qry->Fetch() ) {
96 $tinfo[$track->path_name
] = $track;
101 foreach( $queue AS $k => $track ) {
102 // printf( '<p>%s</p>', $track );
103 $queue[$k] = $tinfo[$track];
106 // Just make sure that's sorted in key order now...