判断flash是否加载完成

来源:互联网 发布:知乎lol与dota2 编辑:程序博客网 时间:2024/03/29 15:45
取得FLASH对象的PercentLoaded方法,看其返回是否为100。
<!doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"  allowfullscreen="true"/>
        <title>FLASH 播放器 by 司徒正美</title>
        <script language="javascript" type="text/javascript"> </script>
        <style type="text/css">
            html, body, #mask{
                width:100%;
                height:100%;
            }
            #mask{
                background:url(http://softwarelivre.sapo.pt/projects/quizcreator/export/13/trunk/core/res/loading.gif) center center no-repeat;
            }
        </style>
 
    </head>
 
    <body>
        <div id="mask">
            <!--这里是蒙板-->
        </div>
        <div id="player">
            <!--这里是播放器-->
        </div>
 
        <script type="text/javascript">
            
            //通过ID取得页面元素
            function $(id){
                return document.getElementById(id)
            }
            //判定是否加载成功
            function checkLoaded(flash){
                try{
                    return Math.floor(flash.PercentLoaded()) == 100
                }catch(e){
                    return false;
                }
            }
            //取得flash的播放地址
            function getFlashURL(){
                return 'http://player.youku.com/player.php/sid/XMzkwNTgzMTIw/v.swf';
            }
            function createFlashHTML(u,w,h,i,wm,v){
                var g= "";
                if(window.ActiveXObject){
                    g='<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" id="'+i+'" name="'+i+'" border="0" width="'+w+'" height="'+h+'"><param name="movie" value="'+u+'" /><param name="quality" value="high" /><param name="allowScriptAccess" value="always" /><param name="menu" value="false" /><param name="allowFullScreen" value="true" /><param name="wmode" value="'+wm+'" /><param name="flashvars" value="'+v+'" /></OBJECT>'
                }else{
                    g='<embed name="'+i+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" pluginspage=" http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" allowScriptAccess="always" allowFullScreen="true" quality="high" menu="false" wmode="'+wm+'" flashvars="'+v+'" src="'+u+'"></embed>'
                }
                return g;
            }
            var flashHTML = createFlashHTML(getFlashURL(),'100%','100%',"videoPlayer","Opaque","autoPlay=true&isAutoPlay=true&auto=1&playMovie=true&adss=0&api=1");
            $("player").innerHTML = flashHTML
            var flash = $("player").children[0];
            var intervalID =  setInterval(function(){
                if(checkLoaded(flash)){
                    clearInterval(intervalID);
                    $("mask").style.display = "none";
                    intervalID = null;
                }
            },60)
                        
        </script>
    </body>
</html>
原创粉丝点击