网页版Flash播放器的实现

时间:2022-10-04 03:33:17

网页版Flash播放器的实现

【摘 要】本文利用javascript脚本语言,设计并实现了一个网页版的Flash播放器。该播放器可实现网页中Flas的播放、停止、暂停和快进等功能。使用户能更好地控制网页中Flas的播放。

【关键词】Javascript;Flash;播放器;网页

1.引言

在用户浏览网页时,网页中的Flas(格式一般为swf)通常是自动播放的。浏览者是无法控制的,比如暂停、快进或重播等。这往往会影响用户浏览网页时的体验。本文实现了一个网页版的Flash播放器,该网页版Flash播放器能对网页中的Flash播放进行深度控制。

2.Flash播放器的实现

Flash播放器的控制代码用javascript实现,主要通过编写相应的函数控制flas的播放、暂停和快进等。该代码编写到一个脚本文件myFlash.js中,详细代码如下[1][2][3]。

function Flash_embedSWF(srcURL,swfbgColor){

var defaultColor = (document.

bgColor != null) ? document.bgColor“#ffffff”;

var bgcolor =(swfbgColor !

= null) ? swfbgColor :defaultColor;

document.writeln(

D27CDB6E-AE6D-96B8-11cf-

444553540000”’ +

‘codebase=”download.省略/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0”’+

‘ID=”flash” WIDTH=”300” HEIGHT=”300”>’ +

‘’ +

‘’ +

‘’+

‘’+

value=”always”>’ +

‘’ +

bgcolor + ‘”’ + ‘width=”300” height=”300”’+

‘type=”application/x-shockwave-flash”NAME=”flash”’ +‘allowScriptAccess=”

always”swLiveConnect=”true”’+

‘pluginspage=”www.省略/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash”>’);

window.document.flash.Rewind();

}

function buttonClk()

{

switch(event.srcElement.value)

{

case “播放”:

window.document.flash.Play();

break;

case “停止”:

window.document.flash.Rewind();

oButton.style.pixelLeft=10;

break;

case “暂停”:

window.document.flash.stopplay();

break;

case “快进”:

if(window.document.flash.IsPlaying())

window.document.flash.StopPlay();

else

{window.document.flash.gotoframe(window.document.flash.CurrentFrame()+50); oButton.style.pixelLeft=10+290*(oPlayer.CurrentFrame()+1)/oPlayer.TotalFrames;

}

break;

case “快退”:

if(window.document.flash.IsPlaying())

window.document.flash.StopPlay();

else

{

window.document.flash.gotoframe(window.document.flash.CurrentFrame()-50); oButton.style.pixelLeft=10+290*(oPlayer.CurrentFrame()+1)/oPlayer.TotalFrames;

}

break;

}

}

接着制作一个简单的静态网页,调用上面的函数实现对Flash文件的控制。网页代码如下所示[4]。

Flash_embedSWF("12shengxiao.swf");

position:absolute;top:320px;

background:darkviolet;left:10px;

font-size:10px;border:1 solid #cccccc

inset;width:300px;height:

15px;z-index:1;">P

onmousedown="StartDrag(this)" onMouseMove="Drag(this)" onMouseUp="StopDrag(this)" >C

var _gaq = _gaq || [];_gaq.push(['_setAccount', 'UA-22575914-1']);_gaq.push(['_setDomainName', '.省略']);_gaq.push(['_trackPageview']);(function () {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'www') + '.省略/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();var _userid = '';var _siteid =708;var _istoken = 1;var _model = 'Model01'; WebPageSpeed =406; UrchinTrack();

运行结果如图1所示。

3.结束语

本文利用javascript脚本语言,设计并实现了一个网页版的Flash播放器。该播放器可实现网页中Flas的播放、停止、暂停和快进等功能。使用户能更好地控制网页中Flas的播放。这大大提高了用户浏览网页Flas的用户体验。

参考文献:

[1]张孝祥,张红梅,JavaScript网页开发[M].北京:清华大学出版社,2004.1.

[2]周瑞.从零开始学Javascript[M].北京:电子工业出版社,2011.1.

[3]周爱民.Javascript语言精髓与编程实践[M].北京:电子工业出版社,2008.3.

[4]林振荣,王炜立.ASP语言程序设计[M].北京:清华大学出版社,2009.12.

作者简介:赵超(1983―),男,硕士研究生,助教,研究方向:计算机技术与应用。

上一篇:试论STC89C52单片机 下一篇:网络教学资源库建设的必要性与措施