soundManager:预加载多个声音

时间:2014-04-11 19:34:28

标签: javascript audio

我已经在这几个星期了,仍然无法预加载我的所有声音。我已经使用了递归函数,理论上,在第一个声音对象加载之前,它不会创建下一个声音对象。我的31个声音中只有18个似乎正在加载。如果我向onload处理程序添加警报,它会报告一个非常奇怪的结果,例如: " spic loaded" 一遍又一遍,18次,而不是报告每个新声音的id。这是我的两个相关模块的代码。你们有没有想出一种可靠的预加载多种声音的方法?谢谢: - )

Earcons模块:      var Earcons =(function(){      // Earcons就像图标,但使用符号声音而不是图片        var trackUrls = [        " audio / newpage.mp3"," audio / fgrow.mp3"," audio / fshrink.mp3",        " audio / slideright.mp3"," audio / slideleft.mp3"," audio / sdiv.mp3"," audio / tell.mp3&#34 ;,        " audio / office_lobby.mp3"," audio / footstep.mp3"," audio / apple.mp3",        "音频/ typewriter.mp3&#34 ;,        " audio / walking.mp3"," audio / macspeak.mp3"," audio / picklock1.mp3",        " audio / gossip.mp3"," audio / winenter.mp3"," audio / winleave.mp3"," audio / beep.mp3&#34 ];

   var trackTitles = [
   "soundOnLoad", "soundOnGrow", "soundOnShrink", "soundOnSlideRight",
 "soundOnSlideLeft", "soundOnDiv", "soundOnParagraph", "work",
 "soundOnList", "apple", "stype", "walk", "macbook",
 "soundOnLink", "soundOnInput", "winenter", "winleave", "soundOnImage"];

   var trackPtr = 0;

   var getTrackNumber = function (trackName) {
   for (i = 0; i < trackTitles.length; i++) {
     if (trackName == trackTitles[i]) return i;
   }
   return -1;
   };

   var preload = function() {
   if (trackPtr >= trackUrls.length)
     { trackPtr = 0; return; }
   else trackPtr++;
   var soundTrack = soundManager.createSound ({id: "st" + trackPtr + "",
   url: trackUrls[trackPtr],
   autoLoad: true, autoPlay: false,
   onload: function() { preload(); } });
 };

   var unload = function() {
   for (i = 0; i < trackUrls.length; i++) {
     var soundTrack = soundManager.getSoundById ("st" + i);
     soundTrack.unload();
     soundTrack.destruct();
   }
 };

   interface = {
     trackUrls: trackUrls,
     trackTitles: trackTitles,
    getTrackNumber: getTrackNumber,
     preload: preload,
     unload: unload
   };

   return interface;
 } )();

Voice narrations module:
 var Narrations = (function() {
   var trackUrls = [
   "audio/about.mp3", "audio/webtech.mp3", "audio/screenreader.mp3",
   "audio/services.mp3", "audio/stories.mp3", "audio/settings.mp3",
   "audio/feedback.mp3", "audio/display.mp3", "audio/soundset.mp3",
   "audio/voiceset.mp3", "audio/divmain.mp3", "audio/divcenter.mp3",
   "audio/divnav.mp3"];

   var trackTitles = [
 "About This Web App", "Web Development Technologies", "What's A Screen Reader",
 "Services I Can Offer", "Stories, Poetry, Anecdotes", "Settings",
 "Send Me Your Comments", "Display Settings", "Sound Settings",
 "Voice Quality Settings", "div mainContent", "div center", "div navBar"];

 var trackPtr = 0;

 var getTrackNumber = function (trackName) {
   for (i = 0; i < trackTitles.length; i++) {
     if (trackTitles[i] == trackName) return i;
   }
   return -1;
 };

 var preload = function() {
   if (trackPtr >= trackUrls.length)
   { trackPtr = 0; return; }
   else trackPtr++;
   var voiceTrack = soundManager.createSound ({id: "vt" + trackPtr + "",
   url: trackUrls[trackPtr],
   autoLoad: true, autoPlay: false,
   onload: function() { preload(); } });
 };

 var unload = function() {
   for (i = 0; i < trackUrls.length; i++) {
     var voiceTrack = soundManager.getSoundById ("vt" + i);
     voiceTrack.unload();
     voiceTrack.destruct();
   }
 };


 interface = {
   trackUrls: trackUrls,
   trackTitles: trackTitles,
   getTrackNumber: getTrackNumber,
   preload: preload,
   unload: unload
 };

   return interface;
 } )();

0 个答案:

没有答案