From f8c9b673aed08e352e95fb7e43ccdcf3b7888506 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 25 May 2008 20:17:21 +1200 Subject: [PATCH] Support VLC as a backend. --- inc/adornoPlayer.php | 1 + inc/daemonInterface.php | 9 ++++----- inc/mpdPlayer.php | 1 + inc/vlcPlayer.php | 19 ++++++++++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/inc/adornoPlayer.php b/inc/adornoPlayer.php index aa4b7f4..4fd4fd7 100644 --- a/inc/adornoPlayer.php +++ b/inc/adornoPlayer.php @@ -1,5 +1,6 @@ daemon_type ); function daemon_play_track( $path ) { $fifo = fopen( "/var/run/adorno/fifo", "w" ); fputs( $fifo, "queue $path\n" ); diff --git a/inc/daemonInterface.php b/inc/daemonInterface.php index 447e2ba..cc7e6ac 100644 --- a/inc/daemonInterface.php +++ b/inc/daemonInterface.php @@ -1,10 +1,9 @@ daemon_type == 'mpd' ) { - include("mpdPlayer.php"); -} -else { - include("adornoPlayer.php"); +switch ( $c->daemon_type ) { + case 'mpd': include("mpdPlayer.php"); break; + case 'vlc': include("vlcPlayer.php"); break; + default: include("adornoPlayer.php"); } /** diff --git a/inc/mpdPlayer.php b/inc/mpdPlayer.php index 39281f6..ce30e09 100644 --- a/inc/mpdPlayer.php +++ b/inc/mpdPlayer.php @@ -1,5 +1,6 @@ daemon_type ); class mpdConnection { var $active; // Once it actually is... var $mpd; diff --git a/inc/vlcPlayer.php b/inc/vlcPlayer.php index 4aae079..d1c9d7d 100644 --- a/inc/vlcPlayer.php +++ b/inc/vlcPlayer.php @@ -1,5 +1,6 @@ daemon_type ); class vlcConnection { var $active; // Once it actually is... var $vlc; @@ -20,8 +21,16 @@ class vlcConnection { function Connect() { global $c; - $this->vlc = stream_socket_client($c->vlc['connection'], $errno, $errstr, 2); - $this->active = true; + if ( ! $this->vlc ) { + $this->vlc = stream_socket_client($c->vlc['connection'], $errno, $errstr, 1); + if ( ! $this->vlc ) { + error_log( sprintf( "vlcPlayer: ERROR: Failed to connect to '%s'. Error %d: %s", $c->vlc['connection'], $errno, $errstr) ); + $this->vlc = 'connection failed'; + return; + } + error_log( "vlcPlayer: Connected to ".$c->vlc['connection'] ); + $this->active = true; + } } /** @@ -30,6 +39,9 @@ class vlcConnection { function Daemon( $say, $end_pattern = 'command' ) { if ( ! $this->active ) $this->Connect(); + $result = (object) array( 'text' => "" ); + if ( ! $this->active ) return $result; + if ( $end_pattern == 'command' ) { $command = preg_replace( '/\s.*$/', '', $say); $end_pattern = "^$command: returned (\d+) \((.+)\)"; @@ -39,7 +51,6 @@ class vlcConnection { fwrite($this->vlc, $say ); stream_set_timeout($this->vlc, 0, 50000); - $result = (object) array( 'text' => "" ); while ( ! feof($this->vlc) ) { $line = fgets($this->vlc, 8192); // echo "

$line

\n"; @@ -50,6 +61,8 @@ class vlcConnection { } } + error_log( "vlcPlayer: Returning result of ".$say ); + return $result; } -- 2.11.4.GIT