Skip to content
Permalink
Browse files

Merge pull request #596 from tarasfrompir/patch-7

add setPlayerVolume function
  • Loading branch information...
sergejey committed Aug 15, 2019
2 parents 8ea3b84 + cdd5f8e commit 135c1bccdc1f97f335f92dbfc1eb951bed5da39b
Showing with 195 additions and 165 deletions.
  1. +1 −165 lib/common.class.php
  2. +194 −0 lib/terminals.class.php
@@ -649,70 +649,6 @@ function playSound($filename, $exclusive = 0, $priority = 0)
eval(SETTINGS_HOOK_AFTER_PLAYSOUND);
}
/**
* Summary of playMedia
* @param mixed $path Path
* @param mixed $host Host (default 'localhost')
* @return int
*/
function playMedia($path, $host = 'localhost', $safe_play = FALSE)
{
if (defined('SETTINGS_HOOK_PLAYMEDIA') && SETTINGS_HOOK_PLAYMEDIA != '') {
eval(SETTINGS_HOOK_PLAYMEDIA);
}
if (!$terminal = getTerminalsByName($host, 1)[0]) {
$terminal = getTerminalsByHost($host, 1)[0];
}
if (!$terminal['ID']) {
$terminal = getTerminalsCanPlay(1)[0];
}
if (!$terminal['ID']) {
$terminal = getMainTerminal();
}
if (!$terminal['ID']) {
$terminal = getAllTerminals(1)[0];
}
if (!$terminal['ID']) {
return 0;
}
$url = BASE_URL . ROOTHTML . 'ajax/app_player.html?';
$url .= "&command=" . ($safe_play ? 'safe_play' : 'play');
$url .= "&terminal_id=" . $terminal['ID'];
$url .= "&param=" . urlencode($path);
getURLBackground($url);
return 1;
}
function stopMedia($host = 'localhost')
{
if (!$terminal = getTerminalsByName($host, 1)[0]) {
$terminal = getTerminalsByHost($host, 1)[0];
}
if (!$terminal['ID']) {
$terminal = getTerminalsCanPlay(1)[0];
}
if (!$terminal['ID']) {
$terminal = getMainTerminal();
}
if (!$terminal['ID']) {
$terminal = getAllTerminals(1)[0];
}
if (!$terminal['ID']) {
return 0;
}
$url = BASE_URL . ROOTHTML . 'ajax/app_player.html?';
$url .= "&command=stop";
$url .= "&terminal_id=" . $terminal['ID'];
getURLBackground($url);
return 1;
}
/**
* Summary of runScript
* @param mixed $id ID
@@ -1246,29 +1182,6 @@ function getPassedText($updatedTime)
return $passedText;
}
function getMediaDurationSeconds($file)
{
if (!defined('PATH_TO_FFMPEG')) {
if (IsWindowsOS()) {
define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe');
} else {
define("PATH_TO_FFMPEG", 'ffmpeg');
}
}
$dur = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1");
if (preg_match("/: Invalid /", $dur)) {
return false;
}
preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $dur, $duration);
if (!isset($duration[1])) {
return false;
}
$hours = $duration[1];
$minutes = $duration[2];
$seconds = $duration[3];
return $seconds + ($minutes * 60) + ($hours * 60 * 60);
}
/**
* Encode/Decode a string for safe transfer to a URL
* @param mixed $string String
@@ -1384,83 +1297,6 @@ function hsvToHex($h, $s, $v)
return sprintf("%02x%02x%02x", $rgb[0], $rgb[1], $rgb[2]);
}
/**
* Summary of player status
* @param mixed $host Host (default 'localhost') name or ip of terminal
* @return 'id' => (int), //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
* 'name' => (string), //Playback status. String: stopped/playing/paused/transporting/unknown
* 'file' => (string), //Current link for media in device. String.
* 'track_id' => (int)$track_id, //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
* 'length' => (int)$length, //Track length in seconds. Integer. If unknown = 0.
* 'time' => (int)$time, //Current playback progress (in seconds). If unknown = 0.
* 'state' => (string)$state, //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.
*/
function getPlayerStatus($host = 'localhost')
{
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 = 'pl_get'; // Команда
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
$terminal = array();
if ($player->json['success'] && is_array($player->json['data'])) {
$terminal = array_merge($terminal, $player->json['data']);
//DebMes($player->json['data']);
} else {
// Если произошла ошибка, выводим ее описание
return ($player->json['message']);
}
$player->command = 'status'; // Команда
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
if ($player->json['success'] && is_array($player->json['data'])) {
$terminal = array_merge($terminal, $player->json['data']);
//DebMes($player->json['data']);
return ($terminal);
} else {
// Если произошла ошибка, выводим ее описание
return ($player->json['message']);
}
}
/**
* 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; // Параметр
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
return $player->json['message'];
}
function remote_file_exists($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
@@ -1491,4 +1327,4 @@ function logAction($action_type,$details='') {
$rec['IP']=$_SERVER['REMOTE_ADDR'];
SQLInsert('actions_log',$rec);
}
}
@@ -142,3 +142,197 @@ function getLocalIp() {
}
return $local_ip_address;
}
/**
* 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; // Параметр
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
return $player->json['message'];
}
/**
* Summary of player status
* @param mixed $host Host (default 'localhost') name or ip of terminal
* @return 'id' => (int), //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
* 'name' => (string), //Playback status. String: stopped/playing/paused/transporting/unknown
* 'file' => (string), //Current link for media in device. String.
* 'track_id' => (int)$track_id, //ID of currently playing track (in playlist). Integer. If unknown (playback stopped or playlist is empty) = -1.
* 'length' => (int)$length, //Track length in seconds. Integer. If unknown = 0.
* 'time' => (int)$time, //Current playback progress (in seconds). If unknown = 0.
* 'state' => (string)$state, //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.
*/
function getPlayerStatus($host = 'localhost')
{
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 = 'pl_get'; // Команда
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
$terminal = array();
if ($player->json['success'] && is_array($player->json['data'])) {
$terminal = array_merge($terminal, $player->json['data']);
//DebMes($player->json['data']);
} else {
// Если произошла ошибка, выводим ее описание
return ($player->json['message']);
}
$player->command = 'status'; // Команда
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
if ($player->json['success'] && is_array($player->json['data'])) {
$terminal = array_merge($terminal, $player->json['data']);
//DebMes($player->json['data']);
return ($terminal);
} else {
// Если произошла ошибка, выводим ее описание
return ($player->json['message']);
}
}
function getMediaDurationSeconds($file)
{
if (!defined('PATH_TO_FFMPEG')) {
if (IsWindowsOS()) {
define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe');
} else {
define("PATH_TO_FFMPEG", 'ffmpeg');
}
}
$dur = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1");
if (preg_match("/: Invalid /", $dur)) {
return false;
}
preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $dur, $duration);
if (!isset($duration[1])) {
return false;
}
$hours = $duration[1];
$minutes = $duration[2];
$seconds = $duration[3];
return $seconds + ($minutes * 60) + ($hours * 60 * 60);
}
/**
* Summary of playMedia
* @param mixed $path Path
* @param mixed $host Host (default 'localhost')
* @return int
*/
function playMedia($path, $host = 'localhost', $safe_play = FALSE)
{
if (defined('SETTINGS_HOOK_PLAYMEDIA') && SETTINGS_HOOK_PLAYMEDIA != '') {
eval(SETTINGS_HOOK_PLAYMEDIA);
}
if (!$terminal = getTerminalsByName($host, 1)[0]) {
$terminal = getTerminalsByHost($host, 1)[0];
}
if (!$terminal['ID']) {
$terminal = getTerminalsCanPlay(1)[0];
}
if (!$terminal['ID']) {
$terminal = getMainTerminal();
}
if (!$terminal['ID']) {
$terminal = getAllTerminals(1)[0];
}
if (!$terminal['ID']) {
return 0;
}
$url = BASE_URL . ROOTHTML . 'ajax/app_player.html?';
$url .= "&command=" . ($safe_play ? 'safe_play' : 'play');
$url .= "&terminal_id=" . $terminal['ID'];
$url .= "&param=" . urlencode($path);
getURLBackground($url);
return 1;
}
/**
* Summary of stopMedia
* @param mixed $host Host (default 'localhost')
* @return int
*/
function stopMedia($host = 'localhost')
{
if (!$terminal = getTerminalsByName($host, 1)[0]) {
$terminal = getTerminalsByHost($host, 1)[0];
}
if (!$terminal['ID']) {
$terminal = getTerminalsCanPlay(1)[0];
}
if (!$terminal['ID']) {
$terminal = getMainTerminal();
}
if (!$terminal['ID']) {
$terminal = getAllTerminals(1)[0];
}
if (!$terminal['ID']) {
return 0;
}
$url = BASE_URL . ROOTHTML . 'ajax/app_player.html?';
$url .= "&command=stop";
$url .= "&terminal_id=" . $terminal['ID'];
getURLBackground($url);
return 1;
}
/**
* This function change volume on the terminal
* @param mixed $host Host (default 'localhost') name or ip of terminal
* @param mixed $level level of volume (default 0) to positon from start time
*/
function setPlayerVolume($host = 'localhost', $level = 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 = 'set_volume'; // Команда
$player->param = $level; // Параметр
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
return $player->json['message'];
}

0 comments on commit 135c1bc

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