<?php
$porta = query_string('1');

if(!is_numeric($porta)) {
die ("Error! Missing data.");
}

$verifica_stm = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".$porta."'"));

if($verifica_stm == 0) {
die ("Error! Missing data.");
}

$dados_config = @mysqli_fetch_array(@mysqli_query($conexao,"SELECT * FROM configuracoes"));
$dados_stm = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".$porta."'"));
$dados_servidor = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor"]."'"));

$total_pontos = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM multipoint where codigo_stm = '".$dados_stm["codigo"]."'"));

if($total_pontos > 0) {
$ponto = "/1";
} else {
$ponto = "/stream";
}

$url_streaming = "https://".strtolower($dados_servidor["nome"]).".".$dados_config["dominio_padrao"].":".$dados_stm["porta"].$ponto;

?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/sonic/jquery.min.js"></script>
<link href='/sonic/widgets.css' media="screen" rel="stylesheet" type="text/css">
<link href='/sonic/flatie.jplayer.skin.css' media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/sonic/jquery.jplayer.min.js"></script>
<script type="text/javascript" src='/sonic/flatie.jplayer.skin.js'></script>
<script src="/sonic/jquery.marquee.min.js" type="text/javascript"></script>
<link href='/sonic/animate.css' media="screen" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">body{overflow: hidden;}.duration{display: none};</style>
</head>

<body>
<div class="se-pre-con"></div>
<script>
$.urlParam = function (name) {
    var results = new RegExp('[\?&]' + name + '=([^&#]*)')
                      .exec(window.location.search);

    return (results !== null) ? results[1] || 0 : false;
}
var ts = new Date().getTime();
$(window).on('load', function(){ $(".se-pre-con").fadeOut("slow"); });

function animateCSS(element, animationName, callback) {
if (!document.hidden) {
    const node = document.querySelector(element)
    node.classList.add('animated', animationName)

    function handleAnimationEnd() {
        node.classList.remove('animated', animationName)
        node.removeEventListener('animationend', handleAnimationEnd)

        if (typeof callback === 'function') callback()
    }

    node.addEventListener('animationend', handleAnimationEnd)
}}

$(document).ready(function(){
$.get("/musica-atual/<?php echo $dados_stm["porta"]; ?>" ,function(data){ var musica = data.replace(/_/g," ");$("#nowplay").html(musica);

	$('.marquee').marquee({
	//duration in milliseconds of the marquee
	duration: 5000,
	//gap in pixels between the tickers
	gap: 50,
	//time in milliseconds before the marquee will start animating
	delayBeforeStart: 100,
	//'left' or 'right'
	direction: 'left',
	//true or false - should the marquee be duplicated to show an effect of continues flow
	duplicated: false,
	pauseOnHover: true
});
load_cover(data);
 animateCSS('#playertrack', 'rubberBand') });
intervalplay = setInterval(function() {
$.get("/musica-atual/<?php echo $dados_stm["porta"]; ?>" ,function(data){ var musica = data.replace(/_/g," ");$("#nowplay").html(musica);

	$('.marquee').marquee({
	//duration in milliseconds of the marquee
	duration: 5000,
	//gap in pixels between the tickers
	gap: 50,
	//time in milliseconds before the marquee will start animating
	delayBeforeStart: 0,
	//'left' or 'right'
	direction: 'left',
	//true or false - should the marquee be duplicated to show an effect of continues flow
	duplicated: false,
	pauseOnHover: true
});
load_cover(data);
animateCSS('#playertrack', 'rubberBand')  });
}, 20000);

});

	$(document).ready(function() {
	$('#player1').flatie({
	media: {
	m4a: "<?php echo $url_streaming; ?>"
	},
	solution: 'html, flash',
	supplied: "m4a",
	preload: 'auto',
	autoplay: true,	volume: '1.0'

	});



	});
	function load_cover(e){var t=e.substr(0,e.indexOf("-")).trim().replace(" ","-");fetch("https://itunes.apple.com/search?term="+t+"&media=music&limit=1").then(e=>e.text()).then(function(e){var t=JSON.parse(e).results[0].artworkUrl100;$('#art').fadeOut().queue(function() {
   var img = $(this);
   img.attr('src', t);
   img.fadeIn();
   img.dequeue();
});})}
</script>
</head>



  <table>
  <tbody>
  <tr>
  <td>
  <div><img id="art" src="/img/img-player-full-capa.png" width="102" height="102" border="0" style="border-radius: 10px 0 0 10px;"></div>
  </td>
  <td style='width: 100%; height: 100%;'>
  <span class="weburl" style="color:black;"></span>
    <div class="nowplay"><img src="/sonic/now5.png" id="playertrack" style="vertical-align: middle;" alt="" border="0"><span class="nowplaytext" style="color:black;"></span> <div class='marquee' style="color:#474747;" id='nowplay'></div></div>
    <div id="player1" class="jPlayer audioPlayer light" style='border-radius: 0 10px 10px 0;'></div>
  </td>
  </tr>
  </tbody>
  </table>




</body>
</html>
