<?
$docroot ="/var/www/antiuser/data/www/";
include_once( "../inc.php" );
$server = "91.221.70.37";
$protocol = "rtmp://";
$application = "live";
$stream = "cam";
$channel_data = array();
$rtmpS = array();
$pathS = array();
$loc = $_SERVER["PHP_SELF"];
$w = 340; $h = 240;
if( isset( $_GET["id"] )){
    $_GET["id"] = (int) $_GET["id"] ;
    $channel_data = $chanel_list->get_channel_by_id($_GET["id"]);
    $loc = "$loc?id=$_GET[id]";
}
if( isset($channel_data["rtmp"]) ){
    $rtmpS = $chanel_list->parse_rtmpname( $channel_data["rtmp"] );
}
$mediaurl = "http://media.ov-russa.ru";

?>

<? 
if( count( $rtmpS ) > 0  ){
	//=========06.09.2018 ПРОВЕРКА НА ВИДЕО. ЕСЛИ ФАЙЛ - НЕ ВИДЕО, ОКНО ОТКРЫВАЕТСЯ БЕЗ ПЛЕЕРА==================
	$ext = end(explode(".",$rtmpS[0]["url_filename"]));
	if ($ext != "mp4"){
		header('Location: '.$rtmpS[0]["url_filename"]);
	}
	//==========================================================================================================
    ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>
    <? if( count( $channel_data) > 0){
        if( isset($channel_data["title"]) ){
            $channel_data["title"] = str_replace("$$$", " ", $channel_data["title"]);
            $channel_data["title"] = str_replace("^^^", " ", $channel_data["title"]);
        ?>
       <?=$channel_data["title"] ?>
        <?}?>
    <?}?>
    </title>
    
        <link rel="stylesheet" type="text/css" href="vidcontent_.css">
        
        <script src="../jquery-1.11.3.min.js"></script>
        
        <script src="../jwplayer/jwplayer.js"></script>
    
        <script>jwplayer.key = "4Hu5eE2RAUX7C7pqBAolRxui0awHk+Z3z6ix0w==";</script>
    
        <script>
onload = function(){
    $("body").css("overflow", "hidden");
    $("#videocontent").css("overflow", "hidden");
    $("#btnsupport").css("overflow", "hidden");
    window.WD = window.innerWidth;
    window.HT = window.innerHeight;
    window.LT = window.screenLeft ? window.screenLeft : window.screenX;
    window.TP = window.screenTop ? window.screenTop : window.screenY;
    
    $("#res640").css("margin-left", $("#res640").width()+"px");
    $("#res480").css("margin-left", $("#res480").width()+"px");
    $("#res320").css("margin-left", $("#res320").width()+"px");
    
    setWinSize();
    
    
 
    $( window ).resize(function() {
       setWinSize()
    });
}  
    setWinSize = function(){
       WWW = $(window).width();
       HHH = $(window).height(); 
        if(  WWW > 1000 || HHH > 500 ){        
            WWW = 2*WWW/3;
            HHH = 3*HHH/4 ;
        }
       
       if( HHH < 350 ){
           HHH = 350
           window.innerHeight = 350;
       }
       if( HHH > 1000 ){
           HHH = 1000
           window.innerHeight = 800;
       }
       
       if( WWW < 310 ){
           WWW = 310
           window.innerWidth = 310;
       }
       if( WWW > 1200 ){
           WWW = 1200
           window.innerWidth = 1200;
       }
       X = ( $(window).width() - WWW)/2;
       Y = ( $(window).height() - HHH)/2;
       
       $("#videocontent").css("width", WWW+"px" );
       $("#videocontent").css("height", HHH+"px" );
       $("#videocontent").css("left", X+"px" );
       $("#videocontent").css("top", Y+"px" );
       
       
       
       window.jp.resize(WWW,  HHH - $("#btnsupport").height()-10);
       
    }      
    
        </script>
</head>

<body>
    

    <?
    $fn = explode(".mp4", $rtmpS[0]["url_filename"]);
    
    $fileplay = $fn_orig = "$fn[0].mp4";
    $fn_320 = "$fn[0]"."_320.mp4";
    $fn_640 = "$fn[0]"."_640.mp4";
    $fn_480 = "$fn[0]"."_480.mp4";
    
    
    
    @$f = (int) fopen($fn_orig, "r");
    @$f_640 = (int) fopen($fn_640, "r");
    @$f_320 = (int) fopen($fn_320, "r");
    @$f_480 = (int) fopen($fn_480, "r");
    
    if( $f_480 ){
            $fileplay = $fn_480;
    }
    if( isset($_GET["orig"]) ){
        $fileplay =  $fn_orig;
    }
    
    if( isset($_GET["res"]) ){
       if($_GET["res"] == 320 ){
           $fileplay =  $fn_320;
       }
       if($_GET["res"] == 640 ){
           $fileplay =  $fn_640;
       }
       if($_GET["res"] == 480 ){
           $fileplay =  $fn_480;
       }
    }
    //echo (int) $fn_480 ;
    ?>
    
    <div id="videocontent" class="vidcontent">
    <?foreach( $rtmpS as $k => $value  ){?>
    
        <div class="player" id="player<?=$k?>" >Загрузка....</div>
    
    
    <?}?>
    <div id="btnsupport">
           
    <input id="res720" type="button" value="Высокое"
           <? if( $fileplay == $fn_orig ){?>  style=" color: #ffff00;"   <?}?>
           <?if( !$f ){?> style=" color: #777770"  <?}?> 
           <?if( $f ){?>      onclick="
           window.location = '<?=$loc ?>&orig=1';
           "
           <?}?>
           />
           
    <input id="res640"  type="button" value="640"
          <? if( $fileplay == $fn_640 ){?>  style=" color: #ffff00;"   <?}?>
           
           <?if( !$f_640 ){?> style=" color: #777770"  <?}?> 
           <?if( $f_640 ){?>      onclick="
           window.location = '<?=$loc ?>&res=640';
           "
           <?}?>
           />
    
    <input id="res480"  type="button" value="480" 
           <? if( $fileplay == $fn_480 ){?>  style=" color: #ffff00;"   <?}?>
           <?if( !$f_480 ){?> style=" color: #777770"  <?}?> 
           <?if( $f_480 ){?>      onclick="
           window.location = '<?=$loc ?>&res=480';
           "
           <?}?>
           />
    
    <input id="res320"  type="button" value="320" 
           <? if( $fileplay == $fn_320 ){?>  style=" color: #ffff00;"   <?}?>
           <?if( !$f_320 ){?> style=" color: #777770"  <?}?> 
           <?if( $f_320 ){?>      onclick="
           window.location = '<?=$loc ?>&res=320';
           "
           <?}?>
           />
    
    </div>
	
    </div>
	
<script>

    ww = $(document).width(); hh = $(document).height() - $('#btnsupport').height() ;
    
    <? if(  count( $rtmpS ) > 1 ) {?>
        ww = 400; hh = 300 ;
    <?}?>
    <?foreach( $rtmpS as $k => $value  ){
        $valfile = $value["short_filename"]  ;
        ?>
     window.jp = jwplayer("player<?=$k ?>").setup({
       <? if(  count( $rtmpS ) == 1 ) {?>
        autostart: true,
       <?}?>
        sources: [{
        }, {
            file: "<?=$fileplay ?>"
        }],
        image: "<?=$channel_data["icon"] ?>" , 
        title: "<?=$channel_data["title"] ?>" ,
        
        width: window.ww ,
        height: window.hh,
        
        
        stretching:"uniform",
        
        fallback: false
    });
    
    
    
    
    <?}?>
	
</script>

<script>
    
        $('.vidcontent').css('width', ww+'px');
        $('.vidcontent').css('height', (5+$('#btnsupport').height( )+hh)+'px');
    
</script>


<!-- Yandex.Metrika counter --> 
<script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter37477145 = new Ya.Metrika({ id:37477145, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/37477145" style="position:absolute; left:-9999px;" alt="" /></div></noscript> 
<!-- /Yandex.Metrika counter -->

</body>
</html>
<?}?>