русский

Моя золотая мечта 05.01.2025

4 Tage zurück, 23:32
Re: Моя золотая мечта 05.01.2025
 
uscheswoi_82 коренной житель
in Antwort uscheswoi_82 4 Tage zurück, 23:28, Zuletzt geändert 4 Tage zurück, 23:44 (uscheswoi_82)

Аудиопроигрыватель я сделал так audioplayer.js:

var mySound = null;
var timerSound = null;
var currPlayerId = '';
var currDuration = 0;

function ap_tot(s) // to_time
{
  var sec_num = parseInt(s, 10);
  var hours = Math.floor(sec_num / 3600);
  var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
  var seconds = sec_num - (hours * 3600) - (minutes * 60);
  
  if(hours < 10) 
  {
    hours = "0"+hours;
  }  
  if(minutes < 10) 
  {
    minutes = "0"+minutes;
  }
  if(seconds < 10) 
  {
   seconds = "0"+seconds;
  }
  return hours+':'+minutes+':'+seconds;
}

function ap_pbc(c, m) // progress_bar_calculate
{
  return Math.floor((200.0 / m) * c);
}

function ap_fnl(n, l)   // format_number_length
{
  var r = '' + n;
  while(r.length < l)
  {
    r = '0' + r;
  }
  return r;
}

function ap_paa(id) // pause_audio
{
  $$.title('');
  mySound.pause();
  clearInterval(timerSound);
}

function ap_sa(f, t, id) // stop_audio
{
  var p = document.getElementById('img_' + currPlayerId);
  if(p != null)
  {
    p.src = path + 'images/play.png';
    p.id = 'img_' + currPlayerId;
 //   p.setAttribute("onclick", 'ap_pa(\''+ f + '\',\'' + t + '\',' + id + ');');
  }

//  $('play_button_' + currPlayerId).text('<a class="player_button" href="javascript:void(0);" onclick="ap_pa(\''
//  + f + '\',\'' + t + '\',' + id + ');"><img id="img_' + id + '" src="' + path + 
//  'images/play.png" width="20px" height="20px" /></a>');
  mySound.pause(); 
  clearInterval(timerSound);
}

function ap_pa(f, t, id, at)   // play_audio
{
  var duration = 0;
  currPlayerId = id;


  if(mySound != null) ap_sa();


//  $$.title("On air '" + at + "'");
  $$.title(sprintf(__('audio_onair'), at));
  
  mySound = new Audio(path + '/userdata/mp3/' + f);
  mySound.play();
  mySound.volume = ap_gav();


  mySound.progress = function(e) { alert(''); }
  mySound.onloadedmetadata = function() {
    duration = Math.floor(mySound.duration / 60);
    currDuration = mySound.duration;
    
    if(duration > 59)
    {
      $('current_time_' + id).text('00:00:00');
      $('time_' + id).text('01:' + ap_fnl(duration, 2) + ':' + ap_fnl(Math.floor(mySound.duration % 60) , 2));
    }
    else
    {
      $('current_time_' + id).text('00:00');
      $('time_' + id).text(ap_fnl(duration, 2) + ':' + ap_fnl(Math.floor(mySound.duration % 60), 2));
    }
    
    timerSound = setInterval(
      function() 
      { 
        $('play_button_' + currPlayerId).text('<a class="player_button" href="javascript:void(0);" onclick="ap_sa(\''+ f + '\',\'' + t + '\',' +
                                              id + ');"><img id="img_' + id + '" src="' + path + 'images/stop.png" width="20px" height="20px" /></a>');
        $('current_time_' + currPlayerId).text(ap_tot(Math.floor(mySound.currentTime /*% 60*/))); 
        document.getElementById('progress_' + id).style.width = ap_pbc(mySound.currentTime, currDuration) + 'px';
      } 
      , 100);
  }
}

function ap_lsf(u, tr_uploaded)  // load_sound_files
{
  $$.ajax(path + MP3SOUNDSLOAD, 'POST', 'u=' + u, function(sounds) 
  {
    var resp = JSON.parse(sounds);
    var items = '';
    for(var index=0; index<resp.length; index++)
    {
      items += '<div id="player__' + resp[index].audioid + '"><div title="' + sprintf(tr_uploaded, resp[index].flname) +'" id="player_' + index + '"><div>' + resp[index].author + 
               ' - ' + resp[index].title + '</div><table><tr><td><div id="play_button_' + index + '"><a class="player_button" href="javascript:void(0);" onclick="ap_pa(\'' + 
               resp[index].file + '\', \'\',' + index + ', \'' + resp[index].author + ' - ' + resp[index].title + '\')"><img id="img_' + resp[index].audioid + '" src="' + path +
               'images/play.png" width="20px" height="20px" /></a> </td><td class="" style="width:200px;"><div class="_auplayer_none"> </div><div class="_auplayer_pos" style="width:0px;" id="progress_' + 
               index + '"> </div></td><td><span id="current_time_' + index + '">00:00</span> / <span id="time_' + index + '">' + resp[index].length + 
               '</span></td><td><a class="command" href="#javascript:void(0);" onclick="ap_da(' + 
               resp[index].audioid + ');">×</a></tr></table></div></div>
';
    }
    var items2 = '<div id="volume_inner"><a class="command" href="javascript:void(0);" onclick="ap_dec();">-</a> <input type="text" id="volume_value" value="0.5" style="text-align:center; width:50px;"' +
                 ' disabled> <a class="command" href="javascript:void(0);" onclick="ap_inc();">+</a></div>';
    $('volume').text(items2);
    $('sounds').text(items);
  });
}

function ap_sfua(id) // show_form_upload_audio
{
  $$.ajax(path + FORM_AUDIO, 'GET', '', function(form) { $(id).text(form); }); 
}

function ap_sff(fid) // show_find_form 
{
  // fid = form id
  $$.ajax(path + FORM_SEARCH, 'GET', '', function(form) { $(fid).text(form); }); 
}

function ap_hff(fid) // hide_find_form
{
  // fid = form id
  $(fid).text(' ');
}

function ap_fa(s) // find_audio
{
  $$.ajax(path + SEARCH_AUDIO, 'POST', 'title=' + s, function(sounds) 
  {
    var resp = JSON.parse(sounds);
    var items = '';
    for(var index=0; index<resp.length; index++)
    {
      items += '<div id="player__' + resp[index].audioid + '"><div title="Uploaded by ' + resp[index].flname +'" id="player_' + index + '"><div>' + resp[index].author + 
               ' - ' + resp[index].title + '</div><table><tr><td><div id="play_button_' + index + '"><a class="player_button" href="javascript:void(0);" onclick="ap_pa(\'' + 
               resp[index].file + '\', \'\',' + index + ', \'' + resp[index].author + ' - ' + resp[index].title + '\')"><img src="' + path + 
               'images/play.png" width="20px" height="20px" /></a> </td><td class="" style="width:200px;"><div class="_auplayer_none"> </div><div class="_auplayer_pos" style="width:0px;" id="progress_' + 
               index + '"> </div></td><td><span id="current_time_' + index + '">00:00</span> / <span id="time_' + index + '">' + resp[index].length + '</span></td><td><a class="command" id="addb_' + 
               resp[index].audioid + '" href="javascript:void(0);" onclick="ap_aea(' + resp[index].audioid + ');">+</a></tr></table></div></div>
';
    }
    $('sounds').text(items);
  });
}

function ap_da(aid) // delete_audio
{
  $$.ajax(path + DELETE_AUDIO, 'POST', 'aid=' + aid, function(v) {
    $('player__' + aid).css('visibility:hidden');
  });
}

function ap_aea(aid) // add_exist_audio
{
  $$.ajax(path + ADD_AUDIO, 'POST', 'aid=' + aid, function(v) { $('addb_' + aid).text(''); });
}

function ap_sav(volume) // set_audio_volume
{
  LS.set('audio_volume', volume);
  $('volume_value').val(volume);
  mySound.volume = volume;
}

function ap_gav() // get_audio_volume
{
  return parseFloat($('volume_value').val());
}

function ap_inc() // increase
{
  var v = parseFloat($('volume_value').val());
  if(v < 1.00)
    v+=0.01;

  ap_sav(v);
}

function ap_dec() // decrease
{
  var v = parseFloat($('volume_value').val());
  if(v > 0.00)
    v-=0.01;

  ap_sav(v);
}
Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнение
 

Sprung zu