自動根據視頻檔案類型選擇不同播放器的JAVASCRIPT代碼

來源:互聯網
上載者:User
<Script language="jscript.encode"> var LINK = new Array("mms://nv.sina.com.cn/bnpv/2006/06/07706787.wmv","123");
var linkType = new Array();
linkType['WMA'] = 'WMP';
linkType['MP3'] = 'WMP';

linkType['WMV'] = 'WMP';
linkType['ASF'] = 'WMP';
linkType['MPG'] = 'WMP';
linkType['MPGE'] = 'WMP';
linkType['AVI'] = 'WMP';
linkType['ASX'] = 'WMP';

linkType['RM'] = 'Real';
linkType['RMVB'] = 'Real';
linkType['RAM'] = 'Real';

linkType['SWF'] = 'Flash';

linkType['JPG'] = 'Pic';
linkType['JPEG'] = 'Pic';
linkType['GIF'] = 'Pic';
linkType['PNG'] = 'Pic';
linkType['BMP'] = 'Pic';

var linkIcon = new Array();
linkIcon['UNKNOWN'] = "/images/vod/unkown.gif";
linkIcon['RAR'] = "/images/vod/rar.gif";
linkIcon['DOC'] = "/images/vod/doc.gif";
linkIcon['XLS'] = "/images/vod/xls.gif";
linkIcon['PPT'] = "/images/vod/ppt.gif";
linkIcon['HTML'] = "/images/vod/html.gif";
linkIcon['HTM'] = "/images/vod/html.gif";
linkIcon['ASP'] = "/images/vod/html.gif";
linkIcon['PHP'] = "/images/vod/html.gif";
linkIcon['JSP'] = "/images/vod/html.gif";
linkIcon['ASPX'] = "/images/vod/html.gif";
linkIcon['TXT'] = "/images/vod/txt.gif";
linkIcon['ZIP'] = "/images/vod/rar.gif";
linkIcon['XML'] = "/images/vod/xml.gif";
linkIcon['EXE'] = "/images/vod/exe.gif";
linkIcon['MSI'] = "/images/vod/exe.gif";
linkIcon['CHM'] = "/images/vod/chm.gif";
linkIcon['PDF'] = "/images/vod/pdf.gif";

var sufFix = LINK[0].substring(LINK[0].lastIndexOf(".")+1,LINK[0].length).toUpperCase();
if(sufFix.indexOf("#")) sufFix = sufFix.split("#")[0];
if(sufFix.indexOf("?")) sufFix = sufFix.split("?")[0];

function WMP(){
        document.writeln("<OBJECT ID='MediaPlayer' WIDTH=400 HEIGHT="+((sufFix=="MP3"||sufFix=="WMA")?"69":"369")+" CLASSID='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' STANDBY='Loading Windows Media Player components...' TYPE='application/x-oleobject'>");
        document.writeln("<PARAM NAME='FileName' VALUE='"+LINK[0]+"'>");
        document.writeln("<PARAM NAME='ShowStatusBar' VALUE='True'>");
        document.writeln("<PARAM NAME='AutoStart' VALUE='True'>");
        document.writeln("<param name='enableContextMenu' value='false'>");
        document.writeln("<EMBED TYPE='application/x-mplayer2' SRC='"+LINK[0]+"' NAME='MediaPlayer' ShowStatusBar=1 WIDTH=400 HEIGHT="+((sufFix=="MP3"||sufFix=="WMA")?"69":"369")+" enableContextMenu='false'></EMBED>");
        document.writeln("</OBJECT>");

        document.close();
}
function Real(){
        document.writeln("<object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='400' height='300'  id='amourReal'>");
        document.writeln("  <param name='src' value='"+LINK[0]+"'>");
        document.writeln("  <param name='autostart' value='true'>");
        document.writeln("  <param name='controls' value='imagewindow'>");
        document.writeln("  <param name='console' value='clip1'>");
        document.writeln("  <embed src='"+LINK[0]+"' width='400' height='300' type='audio/x-pn-realaudio-plugin' autostart='true' controls='imagewindow' console='video'>");
        document.writeln("  </embed>");
        document.writeln("</object>");
        document.writeln("<br />");
        document.writeln("<object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='400' height='50' id='amourReal'>");
        document.writeln("  <param name='src' value='"+LINK[0]+"'>");
        document.writeln("  <param name='autostart' value='true'>");
        document.writeln("  <param name='controls' value='all'>");
        document.writeln("  <param name='console' value='clip1'>");
        document.writeln("  <embed type='audio/x-pn-realaudio-plugin' src='"+LINK[0]+"' width='400' height='50' autostart='true' controls='all' console='video'>");
        document.writeln("  </embed>");
        document.writeln("</object>");

        document.close();
}

function Flash(){
        document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='600' height='480'>");
        document.write("<param name='movie' value='"+LINK[0]+"'>");
        document.write("<param name='quality' value='high'>");
        document.write("<embed src='"+LINK[0]+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='480' height='330'></embed>");
        document.write("</object>");
        document.close();
}

var tempPic = new Image();
function Pic(){
        document.write("<img name='myPic' src='/images/vod/loading.gif' alt='正在載入圖片...' width=94 height=30>");
        tempPic.onload = function(){
                document.images['myPic'].src = LINK[0];
                document.images['myPic'].alt = LINK[1];
                document.images['myPic'].width = (tempPic.width<500)?tempPic.width:500;
                document.images['myPic'].height = (tempPic.width<500)?tempPic.height:500*tempPic.height/tempPic.width;
                document.images['myPic'].style.cursor = 'pointer';
                document.images['myPic'].onclick=function(){window.open(LINK[0])}
        };
        tempPic.src = LINK[0];
}
function Default(){
        if(linkIcon[sufFix]){
                document.writeln("<img src='"+linkIcon[sufFix]+"' width=16 height=16 align=absmiddle>");
        }else{
                document.writeln("<img src='"+linkIcon['UNKNOWN']+"' width=16 height=16 align=absmiddle>");
        }
       
        document.writeln("<a href='"+ LINK[0] +"' target='_blank'>" + LINK[1] + "</a>");

        document.close();
}

if(linkType[sufFix]){
        eval(linkType[sufFix]+"()");
}else{
        Default();
}
</script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.