/**
** main.js :: Arquivo de funções javascript do player de musica
** @author Lucas Oliveira :: lwagenciaweb@gmail.com
**/
$(function () {
var PLAYER = $('.player');
var PLAY = {
getMusicaAtual: function () {
$.getJSON(PLAYER.data('api'), function (data, status) {
if (data.status == "Ligado") {
var musica_atual = (typeof data.radio_musica_atual === "object" ? document.title : data.musica_atual.replace(/_/g, ' ')); // Mostra a música atual
$('.musica-musica-atual,.contents').find('span').html("");
var $data_capa = (typeof data.capa_musica == 'object' ? 'images/img-capa-artista-padrao.png' : data.capa_musica);
$('.cover-musica').html("");
$('.musica-capa').css({background: 'url(' + $data_capa + ') no-repeat center 100%'});
}
PLAY.invervalo();
});
}, invervalo: function () {
var TimeId = setTimeout(PLAY.getMusicaAtual, 30000);
},
onRadioPlay: function () {
var $this = $(this);
var pl = $this.hasClass('on');
if (!pl) {
PLAY.radio.play();
$this.addClass('on');
$this.html('');
} else {
PLAY.radio.pause();
$this.removeClass('on');
$this.html('');
}
},
onRadioMute: function () {
var $this = $(this);
var pl = $this.hasClass('on');
if (!pl) {
PLAY.radio.volume = 0;
$this.addClass('on');
$this.html('');
} else {
PLAY.radio.volume = 1;
$this.removeClass('on');
$this.html('');
}
},
onRadioInfo: function () {
var $this = $('.musica-capa');
var pl = $this.hasClass('on');
if (!pl) {
$this.addClass('on');
} else {
$this.removeClass('on');
}
},
radio: new Audio($('.player').data('url')), //document.getElementById('radio_player'),
rd: this.radio,
};
$('.musica-pause').on('click', function () {
PLAY.radio.pause();
});
$('.musica-play').on('click',PLAY.onRadioPlay);
$('.musica-vol1').on('click',PLAY.onRadioMute);
$('.btn-infor').on('click',PLAY.onRadioInfo);
// $('.musica-vol2').on('click', function () {
// if (PLAY.radio.volume < 1) {
// PLAY.radio.volume += 0.1;
// }
// });
// $('.musica-vol1').on('click', function () {
// if (PLAY.radio.volume > 0) {
// PLAY.radio.volume -= 0.1;
// }
// });
$('.jp-mute').on('click', function () {
PLAY.radio.volume = 0;
})
PLAY.getMusicaAtual();
var radioVolume = function () {
var volume;
if (g.getValue() == 10) {
volume = '1';
} else {
volume = "0." + g.getValue();
}
PLAY.radio.volume = volume;
};
var g = $('#volume').slider({tooltip: 'always'}).on('slide', radioVolume).data('slider');
});