【问题标题】:How do I preload flash video and images?如何预加载 Flash 视频和图像?
【发布时间】:2012-03-14 11:40:32
【问题描述】:

我正在开发一个通过 ajax 处理“页面”的 web 应用程序。每个页面的内容都在一个 xml 文件中,应用程序 ajax 的那个 xml 文件并从中构建页面,然后将其吐出到浏览器。

其中一些页面有视频或大图像,我试图在前一页上预加载。下面是我用来检查媒体是否已预加载的代码,但是当我登陆页面时,它似乎再次加载它......有什么想法吗?

视频播放器始终存在于 dom 中,当它不被使用时,我将其隐藏在屏幕之外。

我假设使用新的 Image() 并给它一个源缓存该图像太对了吗?

var l_image = new Image();
//other stuff happens here

switch(l_next.type) {
    case 'st_animation':
      if(l_next.video != undefined && l_next.video != '') {
        l_videoSrc = String(l_next.video);
        _videoPlayer.loadVideo(l_videoSrc);
        delete l_next;
      }
      //give 2secs for the video to load atleast the first frame
      setTimeout(p_callback, 2000);
      break;

    default:
      if(l_next.image != undefined && l_next.image != '') {
        l_imageSrc = 'files/'+ l_next.image;
        delete l_next;
        l_image.src = l_imageSrc;
        //replace the image or append it
        if(this.data.type == 'st_animation') {
          _$image.html('<img src="'+ l_imageSrc +'" alt="" />');
        }
        else {
          _$image.prepend('<img src="'+ l_imageSrc +'" alt="" />');
        }
        //trigger callback when loaded
        if(l_image.complete) {
          setTimeout(p_callback, 500);
        }
        else {
          l_image.onload = function() {
            setTimeout(p_callback, 500);
          }
        }
      }

还有回调函数:

/*
 * Goes to the page with the specified id
 */
goTo : function(p_pageID) {
  //empty content & show loader
  _$content.empty();
  _currentPage = null; //empty the page data
  //_$loader.fadeIn(500);
  //get the page we're going to's data
  var l_data = this.getData(p_pageID);
  //instantiate this pages PageType sub-class
  eval('_currentPage = new '+ l_data.type +'(l_data)');
  l_data = null;
},


/**
 * Loads the xml of the page's id you pass it
 */
getData : function(p_pageID) {
  var l_cacheBuster = '?cacheBuster='+ _structure.course.settings.cache_buster,
      l_xmlPath = './data/'+ p_pageID +'.xml'+ l_cacheBuster,
      l_data = new Object();
  //ajax request
  $.ajax({
    type: 'GET',
    url: l_xmlPath,
    dataType: 'xml',
    async: false,
    success: function(p_data) {
      //convert the xml structure to json
      l_data = $.xml2json(p_data);
      //check for parsing error
      if(l_data.text != undefined) {
        var l_dataString = String(l_data);
        if(l_dataString.indexOf('XML Parsing Error') > -1) {
          trace(l_dataString);
        }
      }
    },
    error: function(p_response, p_status, p_error) {
      trace('Could not load "'+ l_xmlPath +"\"\r\n"+ p_status +': '+ p_error.name);
    }
  });
  return l_data;
}

提前谢谢...

【问题讨论】:

    标签: javascript jquery flash xhtml preloading


    【解决方案1】:

    图片预加载已解决,无需reinvent-the-wheel。由于 Flash 控制视频,preloading the swf 必须使用 ActionScript。

    参考文献

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2014-08-02
      • 2023-03-25
      • 2014-05-13
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多