我自己也没真正在项目中使用过swfobject这款开源javascript框架,看到有使用该框架做视频类项目的,于是大致看了一下,记录下来,以后用到的话能快速上手.
先介绍一下swfobject框架:
An open source Javascript framework for detecting the Adobe Flash Player plugin and embedding Flash (swf) files.
翻译过来就是,这是一款用于检测Adobe Flash Player插件和嵌入Flash(swf)文件的开源JavaScript框架.
官网地址:http://jquery.thewikies.com/swfobject/
至于使用,像javascript框架jquery框架使用方法都大同小异
引入需要的javascript文件,这个官网有,开始调用吧
<html>
<head>
<title>My JSP 'swf.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script src="http://jquery.thewikies.com/swfobject/jquery.swfobject.1-1-1.js"></script>
<script>
flashMovie = null;
$(document).ready(
function () {
flashMovie = $('#flashInteract .movie');
flashMovie.flash(
{
swf: 'http://127.0.0.1/xxx/xxx/01.swf',//待加载swf文件
width:800,//视频宽
height:500,//高
play: true,//初始加载自动播放
flashvars: {
message: 'I come from Flash.'
},
}
);
}
);
function play() {
flashMovie.flash(
function() {
this.Play();
}
);
}
function pause() {
flashMovie.flash(
function() {
this.StopPlay();
}
);
}
function firstFrame() {
flashMovie.flash(
function() {
this.GotoFrame(0);
}
);
}
function lastFrame() {
flashMovie.flash(
function() {
this.GotoFrame(9);
}
);
}
function prevFrame() {
flashMovie.flash(
function() {
var currentFrame = this.TGetProperty('/', 4),
previousFrame = parseInt(currentFrame) - 2;
if (previousFrame < 0) {
previousFrame = 9;
}
this.GotoFrame(previousFrame);
}
);
}
function nextFrame() {
flashMovie.flash(
function() {
var currentFrame = this.TGetProperty('/', 4),
nextFrame = parseInt(currentFrame);
if (nextFrame >= 10) {
nextFrame = 0;
}
this.GotoFrame(nextFrame);
}
);
}
function sendToFlash() {
flashMovie.flash(
function() {
this.SetVariable('/:message', document.getElementById('data').value);
}
);
}
function getFromFlash() {
flashMovie.flash(
function() {
document.getElementById('data').value = this.GetVariable('/:message');
}
);
}
</script>
</head>
<body>
<div id="flashInteract">
<div class="movie"></div>
<p style="font-family: arial;">
<input type="button" οnclick="firstFrame();" value="回到开头" />
<input type="button" οnclick="prevFrame();" value="快退" />
<input type="button" οnclick="play();" value="播放" />
<input type="button" οnclick="pause();" value="暂停" />
<input type="button" οnclick="nextFrame();" value="快进" />
<input type="button" οnclick="lastFrame();" value="回到结尾" />
</p>
<p>
<input type="text" value="I come from javascript." size="20" οnfοcus="this.select();" id="data" />
<input type="button" οnclick="sendToFlash();" value="Send to Flash" />
<input type="button" οnclick="getFromFlash();" value="Get from Flash" />
</p>
</div>
</body>
</html>
01.swf时我们要加载的swf文件
效果图:
如有错误,欢迎指正
end