1

私は、ajax を介して「ページ」を進行する webapp に取り組んでいます。各ページのコンテンツは xml ファイルにあり、アプリの ajax はその xml ファイルからページを構築し、それをブラウザーに吐き出します。

これらのページの一部には、前のページでプリロードしようとしているビデオまたは大きな画像があります。以下は、メディアがプリロードされているかどうかを確認するために使用しているコードですが、ページにアクセスすると、再度ロードされているようです...何かアイデアはありますか?

ビデオ プレーヤーは常に dom に表示されます。使用されていないときは、画面から非表示にします。

new 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;
}

前もって感謝します...

4

1 に答える 1

0

画像のプリロードは解決済みの問題なので、一からやり直す必要はありません。Flash はビデオを制御するため、swf のプリロードはActionScript で行う必要があります。

参考文献

于 2012-05-16T23:25:49.380 に答える