Skip to content
Permalink
Browse files

Merge pull request #521 from tarasfrompir/patch-1

Исправлено получение информации от Гугл хом колонки
  • Loading branch information...
sergejey committed Apr 11, 2019
2 parents f5db1a8 + e326ca1 commit 6837f4b91e9618b0fed3a07cc80ef6fa31f4d134
@@ -13,46 +13,72 @@ function __construct($terminal) {
$this->terminal = $terminal;
$this->reset_properties();
// Network
$this->terminal['PLAYER_PORT'] = (empty($this->terminal['PLAYER_PORT'])?8009:$this->terminal['PLAYER_PORT']);
// Chromecast
include_once(DIR_MODULES.'app_player/libs/castv2/Chromecast.php');
}
/*
// Get player status
function status() {
$this->reset_properties();
try {
$cc = new GChromecast($this->terminal['HOST'], this->terminal['PLAYER_PORT']);
$cc->requestId = time();
var_dump(
$cc->DMP->getStatus() // TODO
);
//$this->success = TRUE;
//$this->message = 'OK';
//$this->data = array(
// 'track_id' => -1,
// 'length' => 0,
// 'time' => 0,
// 'state' => 'unknown',
// 'volume' => 100,
// 'random' => FALSE,
// 'loop' => FALSE,
// 'repeat' => FALSE,
//);
} catch (Exception $e) {
$this->success = FALSE;
$this->message = $e->getMessage();
// Defaults
$track_id = -1;
$length = 0;
$time = 0;
$state = 'unknown';
$volume = 0;
$random = FALSE;
$loop = FALSE;
$repeat = FALSE;
$cc = new GChromecast($this->terminal['HOST'], $this->terminal['PLAYER_PORT']);
$cc->requestId = time();
$result = $cc->DMP->getStatus();
if ($result) {
$this->reset_properties();
$this->success = TRUE;
$this->message = 'OK';
$this->data = array(
'track_id' => (int)$result['status'][0]['media']['tracks'][0]['trackId'], //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
'length' => (int)$result['status'][0]['media']['duration'], //Track length in seconds. Integer. If unknown = 0.
'time' => (int)$result['status'][0]['currentTime'], //Current playback progress (in seconds). If unknown = 0.
'state' => (string)strtolower($result['status'][0]['playerState']), //Playback status. String: stopped/playing/paused/unknown
'volume' => (int)$volume, // Volume level in percent. Integer. Some players may have values greater than 100.
'random' => (boolean)$random, // Random mode. Boolean.
'loop' => (boolean)$loop, // Loop mode. Boolean.
'repeat' => (boolean)$repeat, //Repeat mode. Boolean.
);
}
return $this->success;
return $this->success;
}
*/
// Playlist: Get
function pl_get() {
$this->success = FALSE;
$this->message = 'Command execution error!';
$track_id = -1;
$name = 'unknow';
$curren_url = '';
$cc = new GChromecast($this->terminal['HOST'], $this->terminal['PLAYER_PORT']);
$cc->requestId = time();
$result = $cc->DMP->getStatus();
if ($result) {
// Results
$this->reset_properties();
$this->success = TRUE;
$this->message = 'OK';
$this->data = array(
'id' => (int)$result['status'][0]['media']['tracks'][0]['trackId'], //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
'name' => (string)$name, //Current speed for playing media. float.
'file' => (string)$result['status'][0]['media']['contentId'], //Current link for media in device. String.
);
}
return $this->success;
}
// Play
function play($input) {
@@ -14,26 +14,23 @@ public function play($url,$streamType,$contentType,$autoPlay,$currentTime) {
$this->launch();
$json = '{"type":"LOAD","media":{"contentId":"' . $url . '","streamType":"' . $streamType . '","contentType":"' . $contentType . '"},"autoplay":' . $autoPlay . ',"currentTime":' . $currentTime . ',"requestId":'.$this->chromecast->requestId.'}';
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media", $json);
/*
$r = "";
while (!preg_match("/\"playerState\":\"PLAYING\"/",$r)) {
$r = $this->chromecast->getCastMessage();
}
*/
// Grab the mediaSessionId
/*
preg_match("/\"mediaSessionId\":([^\,]*)/",$r,$m);
$this->mediaid = $m[1];
if (preg_match("/\"mediaSessionId\":([^\,]*)/",$r,$m)) {
$this->mediaid = $m[1];
}
if (!$this->mediaid) {
$this->mediaid=1;
}
*/
}
public function getMediaSession() {
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"GET_STATUS", "requestId":'.$this->chromecast->requestId.'}');
$request_started=time();
while ((time()-$request_started)<5 && !$this->chromecast->sessionid) {
while ((time()-$request_started)<2 && !$this->chromecast->sessionid) {
$this->chromecast->getCastMessage();
}
$this->mediaid=$this->chromecast->sessionid;
@@ -76,10 +73,18 @@ public function stop() {
public function getStatus() {
// Stop
$this->launch(); // Auto-reconnects
$this->getMediaSession();
if (!$this->mediaid){
// nothing starting
// надо подумать что отправлять
return false;
}
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"GET_STATUS", "mediaSessionId":' . $this->mediaid . ', "requestId":'.$this->chromecast->requestId.'}');
$r = $this->chromecast->getCastMessage();
preg_match("/{\"type.*/",$r,$m);
return json_decode($m[0]);
while (!preg_match("/\"type\":\"MEDIA_STATUS\"/",$r)) {
$r = $this->chromecast->getCastMessage();
}
$r = substr($r, strpos($r,'{"type'),50000);
return json_decode($r,TRUE);
}
public function Mute() {
@@ -104,4 +109,4 @@ public function SetVolume($volume) {
}
}
?>
?>

0 comments on commit 6837f4b

Please sign in to comment.
You can’t perform that action at this time.