Размер файла: 2.12Kb
$(document).ready(function() {
$(document).ajaxSuccess(function() {
var audioUrl = window.location.href;
var audio = $("#audio-player")[0];
var divJson = $('#playlist-json').text();
if (divJson != '' || typeof divJson != 'undenfined')
{
var arrAudios = $.parseJSON(divJson);
var index = 0;
// if (audioUrl.indexOf('http://siwap.ru/audios') != -1) alert (audioUrl);
arrAudios.forEach(function(haudios)
{
audio.onended = function()
{
index++;
if (audioUrl.indexOf('http://siwap.ru/audios') != -1)
{
$('#play-' + index-1).show();
$('#pause-' + index-1).hide();
}
if(index > arrAudios.length) index = 1;
if (audio.src != haudios.url) audio.src = haudios.url;
audio.play();
if (audioUrl.indexOf('http://siwap.ru/audios') != -1)
{
$('#play-' + index).hide();
$('#pause-' + index).show();
}
$('#audio-player').attr('played-id', index);
}
if (audioUrl.indexOf('http://siwap.ru/audios') != -1)
{
$('body').off('click').on('click', '.audio-play', function (e) {
e.preventDefault();
var audioId = $(this).attr('data-id');
var audioSrc = $('.track-id' + audioId).attr('data-src');
audio.onplay = function() {
var audioPlayedId = $('#audio-player').attr('played-id');
$('.audio-play').each(function(i) {
var audioidd = $(this).attr('data-id');
if ($('#pause-' + audioidd).is(':visible'))
{
if (audioPlayedId != audioidd)
{
// alert('Не совпали: ' + audioidd + ' : ' + audioPlayedId);
$('#play-' + audioidd).show();
$('#pause-' + audioidd).hide();
}
}
});
}
if ($('#play-' + audioId).is(':visible'))
{
$('#play-' + audioId).hide();
$('#pause-' + audioId).show();
if (audio.src != audioSrc) audio.src = audioSrc;
audio.play();
$('#audio-player').attr('played-id', audioId);
}
else
{
$('#play-' + audioId).show();
$('#pause-' + audioId).hide();
audio.pause();
}
});
}
});
}
});
});