2012-02-24 2 views
1

나는 ajax를 통해 '페이지'를 통해 진행되는 webapp에서 작업 중이다. 각 페이지의 내용은 xml 파일에 있으며, app 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; 
} 

감사합니다 ...

답변