Skip to content

Commit

Permalink
Merge pull request #430 from tarasfrompir/patch-6
Browse files Browse the repository at this point in the history
Добавлена функция seek для возвращения на текущую позицию проигрываемого контента
  • Loading branch information
sergejey committed Dec 12, 2018
2 parents 095a339 + 1a74757 commit efb1e6b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
29 changes: 29 additions & 0 deletions lib/common.class.php
Expand Up @@ -1400,3 +1400,32 @@ function getPlayerStatus ($host = 'localhost') {
}
}

/**
* This function change position on the played media in player
* @param mixed $host Host (default 'localhost') name or ip of terminal
* @param mixed $time second (default 0) to positon from start time
*/
function seekPlayerPosition($host = 'localhost',$time=0) {
if(!$terminal = getTerminalsByName($host, 1)[0]) {
$terminal = getTerminalsByHost($host, 1)[0];
}
if(!$terminal) {
return;
}
include_once(DIR_MODULES . 'app_player/app_player.class.php');
$player = new app_player();
$player->play_terminal = $terminal['NAME']; // Имя терминала
$player->command = 'seek'; // Команда
$player->param = $time; // Параметр
DebMes($time);
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);

if($player->json['success']) {
return $player->json['message'];
} else {
return $player->json['message'];
}
}

31 changes: 29 additions & 2 deletions modules/app_player/addons/dnla.addon.php
Expand Up @@ -210,7 +210,30 @@ function previous() {
return $this->success;
}


// Seek
function seek($position) {
$this->reset_properties();
// преобразуем в часы минуты и секунды
$hours = floor($position / 3600);
$minutes = floor($position % 3600 / 60);
$seconds = $position % 60;

DebMes($hours.':'.$minutes.':'.$seconds);
$remote = new MediaRenderer($this->terminal['PLAYER_CONTROL_ADDRESS']);
$response = $remote->seek($hours.':'.$minutes.':'.$seconds);
// создаем хмл документ
$doc = new \DOMDocument();
$doc->loadXML($response);
//DebMes($response);
if($doc->getElementsByTagName('SeekResponse')) {
$this->success = TRUE;
$this->message = 'Position changed';
} else {
$this->success = FALSE;
$this->message = 'Command execution error!';
}
return $this->success;
}
// Set volume
function set_volume($level) {
$this->reset_properties();
Expand All @@ -228,7 +251,7 @@ function set_volume($level) {
DebMes('Громкость на терминале - '.$this->terminal['NAME'].' НЕ ИЗМЕНЕНА ОШИБКА!');
$this->success = FALSE;
$this->message = 'Command execution error!';
}
}
return $this->success;
}

Expand Down Expand Up @@ -257,6 +280,10 @@ function get_volume() {
if ($this->data) {
$this->success = TRUE;
$this->message = 'Volume get';
} else {
DebMes('Громкость на терминале - '.$this->terminal['NAME'].' НЕ ПОЛУЧЕНА ОШИБКА!');
$this->success = FALSE;
$this->message = 'Command execution error!';
}
}
return $this->success;
Expand Down
10 changes: 7 additions & 3 deletions modules/app_player/libs/MediaRenderer/MediaRenderer.php
Expand Up @@ -141,9 +141,13 @@ public function play($url = "") {
return $response;
}

public function seek($unit = 'TRACK_NR', $target = 0) {
$response = $this->sendRequestToDevice('Seek', $args);
return $response['s:Body']['u:SeekResponse'];
public function seek($target = 0) {
$args = array(
'InstanceID' => 0,
'Unit' => 'REL_TIME',
'Target' => $target
);
return $this->sendRequestToDevice('Seek', $args);
}

public function setNext($url) {
Expand Down

0 comments on commit efb1e6b

Please sign in to comment.