Skip to content

Commit

Permalink
Merge pull request #291 from thesoultaker48/alpha
Browse files Browse the repository at this point in the history
VLC: backward compatibility fix
  • Loading branch information
sergejey committed Sep 12, 2018
2 parents 676e90c + 90a5749 commit 99fd6f6
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions modules/app_player/addons/vlc.addon.php
Expand Up @@ -35,6 +35,52 @@ function destroy() {
curl_close($this->curl);
}

// Get product version (for exe files)
private function get_product_version($file) {
if($data = file_get_contents($file)) {
$key = "V\x00S\x00_\x00V\x00E\x00R\x00S\x00I\x00O\x00N\x00_\x00I\x00N\x00F\x00O\x00\x00\x00";
$key_pos = strpos($data, $key);
if($key_pos === FALSE) {
return '';
}
$data = substr($data, $key_pos);
$key = "P\x00r\x00o\x00d\x00u\x00c\x00t\x00V\x00e\x00r\x00s\x00i\x00o\x00n\x00\x00\x00";
$key_pos = strpos($data, $key);
if($key_pos === FALSE) {
return '';
}
$version = '';
$key_pos = $key_pos + strlen($key);
for($i=$key_pos; $data[$i]!="\x00"; $i+=2) {
$version .= $data[$i];
}
return trim($version);
} else {
return NULL;
}
}

// Compare programs versions
private function compare_programs_versions($first, $second) {
$fvc = substr_count($first, '.');
$svc = substr_count($second, '.');
if($fvc > $svc) {
$dvc = $fvc;
} else {
$dvc = $svc;
}
$fvf= explode('.', $first);
$svf = explode('.', $second);
for($i=0;$i<=$dvc;$i++) {
if(intval($svf[$i]) > intval($fvf[$i])) {
return TRUE;
} elseif(intval($svf[$i]) < intval($fvf[$i])) {
return FALSE;
}
}
return FALSE;
}

// Play
function play($input) {
$this->reset_properties();
Expand All @@ -46,9 +92,15 @@ function play($input) {
}
$this->stop();
$vlc_volume = round((int)getGlobal('ThisComputer.volumeMediaLevel') / 100, 2);
// "--volume" not working (see https://trac.videolan.org/vlc/ticket/3913)
// The following parameters require last version of VLC (3.0.4):
$volume_params = '--no-volume-save --mmdevice-volume '.$vlc_volume.' --directx-volume '.$vlc_volume.' --waveout-volume '.$vlc_volume;
$volume_params = '';
if($vlc_version = $this->get_product_version(SERVER_ROOT.'/apps/vlc/vlc.exe')) {
$vlc_version = str_replace(',', '.', $vlc_version);
if(!$this->compare_programs_versions($vlc_version, '3.0.4.0')) {
// "--volume" not working (see https://trac.videolan.org/vlc/ticket/3913)
// The following parameters require last version of VLC (3.0.4):
$volume_params = '--no-volume-save --mmdevice-volume '.$vlc_volume.' --directx-volume '.$vlc_volume.' --waveout-volume '.$vlc_volume;
}
}
curl_setopt($this->curl, CURLOPT_URL, $this->address.'/rc/?command=vlc_play&param='.urlencode($volume_params." '".$input."'"));
if($result = curl_exec($this->curl)) {
if($result == 'OK') {
Expand Down

0 comments on commit 99fd6f6

Please sign in to comment.