随机音频播放器集成了静音按钮

时间:2017-11-17 02:20:43

标签: html5-audio

原谅我的无知。

我正处于js学习曲线的陡峭末端(我已经61岁了,因此突触不会像过去一样发射)。

我使用本网站专家提供的代码从音频文件列表中随机选择:

scope.addLanguageItem = function() {
            $scope.LanguageFormData.language.push({ bName: null, pName: null, pNameSub: null, lFeature: null, lIngredient: null, lInstruction: null, languageCat: null });
            $scope.disablebrand=false;

    };

我在单独的试用版中使用了这段代码,为单个音频文件添加了一个静音按钮,以避免让网站上的访问者感到厌烦:

// JavaScript Document


var collection=[];// final collection of sounds to play
var loadedIndex=0;// horrible way of forcing a load of audio sounds

// remap audios to a buffered collection
function init(audios) {
  for(var i=0;i<audios.length;i++) {
    var audio = new Audio(audios[i]);
    collection.push(audio);
    buffer(audio);
  }
}

// did I mention it's a horrible way to buffer?
function buffer(audio) {
  if(audio.readyState==4)return loaded();
  setTimeout(function(){buffer(audio)},100);
}

// check if we're leady to dj this
function loaded() {
  loadedIndex++;
  if(collection.length==loadedIndex)playLooped();
}

// play and loop after finished
function playLooped() {
  var audio=Math.floor(Math.random() * (collection.length));
  audio=collection[audio];
  audio.play();
  setTimeout(playLooped,audio.duration*1000);
}

// the songs to be played!
init([
  'audio/song1.mp3', 'audio/song2.mp3', 'audio/song3.mp3', 'audio/song4.mp3', 'audio/song5.mp3'
]);

我无法弄清楚如何完成将MUTE功能与RANDOM AUDIO PLAY功能集成。

感谢愿意给我一点指导的人!

0 个答案:

没有答案