Файл: mp3/js/player.js
Строк: 112
<?php
function renameClass(tag, className, classNameNew) {
var res = document.getElementsByTagName(tag)
var l = res.length
for(var i = 0; i < l; i++)
{
if (res[i].className == className) {
res[i].className = classNameNew;
}
}
}
function AjaxDataGet(page) {
var request = new XMLHttpRequest();
var query = document.getElementById('playerQuery').value;
request.open('GET', '?q=files&search=' + query + '&page=' + page + '&ajaxData', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
document.getElementById('ajaxContent').innerHTML = request.responseText;
document.getElementById('PlayerJs').setAttribute('data-ml', 0);
document.getElementById('PlayerJs').setAttribute('data-page', page);
}
};
request.send();
}
function PlayerPlayList() {
return document.getElementsByClassName('mp3list');
}
function PlayerNextFile(ui) {
var prelist = PlayerPlayList();
var s = 0;
var thisFileId = document.getElementById('PlayerJs').getAttribute('data-id');
var endFileId = prelist[prelist.length-1].getAttribute('data-id');
var thisPage = Math.ceil(document.getElementById('PlayerJs').getAttribute('data-page'));
var allPages = document.getElementById('PlayerJs').getAttribute('data-pages');
if (thisFileId == endFileId) {
if (thisPage == allPages)
AjaxDataGet(1);
else
AjaxDataGet(thisPage + 1);
}
var list = PlayerPlayList();
for (var i = 0; i < list.length; i++) {
if ( s == 1 || ui == 1) {
document.getElementById('PlayerJs').setAttribute('data-id', list[i].getAttribute('data-id'))
Player('file', list[i].getAttribute('data-id'));
setTimeout(function() {
Player('play')
}, 2000);
break;
}
if ( list[i].getAttribute('data-id') == thisFileId && thisFileId != endFileId) {
s = 1
}
}
if (s == 0 && ui == 0) {
setTimeout(function() { PlayerNextFile(1) }, 2000)
}
}
function isPlaying() { return !player.paused; }
function updateButtons() {
renameClass('i', 'gfx pause', 'gfx play');
var thisFileId = document.getElementById('PlayerJs').getAttribute('data-id');
if (isPlaying()) {
document.getElementById('mp3play-' + thisFileId).setAttribute('class', 'gfx pause');
document.getElementById('PlayerJs-Play').setAttribute('class', 'gfx pause');
}
}
function playerVolume(event) {
var event = event || window.event;
var width = event.offsetX;
if (width >= 95) {
width = 100;
}
player.volume = (width / 100);
document.getElementById('PlayerJs-Volume-Current').style.width = width + '%';
}
function playerTime(t) {
var str = '';
h = Math.floor(t / 3600)
m = Math.floor((t % 3600) / 60)
s = Math.floor((t % 3600) % 60)
if (h) {
str += ("0"+-~(h-1)).substr(-2,2) + ':';
}
str += ("0"+-~(m-1)).substr(-2,2) + ':';
str += ("0"+-~(s-1)).substr(-2,2);
return str;
}
function playerSeek(event) {
var event = event || window.event;
var position = event.offsetX * 100 / document.getElementById('PlayerJs-Progress').offsetWidth;
var seek = player.duration / 100 * position;
player.currentTime = seek;
}
function Player(com, value)
{
if (com == 'fileId') {
return document.getElementById('PlayerJs').getAttribute('data-id');
}
if (com == 'play') {
player.play();
}
if (com == 'toggle') {
if (value != '0' && document.getElementById('PlayerJs').getAttribute('data-id') != value) {
Player('file', value)
}
else {
if (isPlaying()) {
player.pause();
}
else {
player.play()
}
}
}
if (com == 'pause') {
player.pause();
}
if (com == 'stop') {
player.stop();
}
if (com == 'file') {
document.getElementById('PlayerJs-Download').setAttribute('href', document.getElementById('id' + value).getAttribute('data-download'))
document.getElementById('PlayerJs').setAttribute('data-id', value)
player.src = 'http://poiskm.net/?do=getById&id=' + value;
player.play();
}
}
?>