自动根据视频文件类型选择不同播放器的JAVASCRIPT代码

<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>

你可能感兴趣的:(JavaScript)