您的位置:首页 > 移动开发 > Objective-C

swfobject简单封装

2015-12-21 13:48 791 查看
swfobject简单封装

最近一直在研究web视频播放器,找到好多可行的视频播放器,比如JWplayerflowplayer、原生adobe flash等,最后选择的原生adobe flash,(另外两种其实更好更美观,博主还没研究透...),下面把原生的简单封装介绍下:
(function (jq) {
jq.fn.video = function (o) {
var str = '_video';

var s = "swfs/StrobeMediaPlayback.swf";

var i = jq(this).attr('id');

var w = 640;

var h = 360;

var v = "10.3.0";

var f = {
src:'',//视频地址
streamType:'vod',//点播'vod',直播'live'
autoPlay: false,//自动播放
controlBarAutoHide: false,//自动隐藏控制栏
controlBarPosition: "bottom",//
javascriptCallbackFunction: "onJavaScriptBridgeCreated"
};
//播放器的参数设置
var p = {
quality : "high",
bgcolor : "#000000",
allowscriptaccess : "always",
allowfullscreen : "true",
wmode : "window"//["direct", "opaque", "transparent", "window"]   transparent透明
};
//object的属性设置
var a = {
id : jq(this).attr('id')+str,
name : jq(this).attr('name')+str,
align : "middle"
};

var fn = null;

var img = 'none';

var start = '';
var	duration = '';

v = o.version?o.version:v;
s = o.swf?o.swf:s;
w = o.width?o.width:w;
h = o.height?o.height:h;
v = o.version?o.version:v;
f.src = o.src?o.src:f.src;
f.streamType = o.type?o.type:f.streamType;
f.autoPlay = o.autoplay?o.autoplay:f.autoPlay;
f.controlBarAutoHide = o.autohide?o.autohide:f.controlBarAutoHide;
p.quality = o.quality?o.quality:p.quality;
p.bgcolor = o.bgcolor?o.bgcolor:p.bgcolor;
p.allowfullscreen = o.allowfullscreen?o.allowfullscreen:p.allowfullscreen;
p.wmode = o.wmode?o.wmode:p.wmode;
a.id = o.id?o.id:a.id;
a.name = o.name?o.name:a.name;

fn = o.callbackfn?o.callbackfn:fn;

img = o.img?o.img:img;

start = o.start?o.start:'';
duration = o.duration?o.duration:'';
f.src += start==''?'':'&wowzadvrplayliststart='+start;
f.src += (start==''||duration=='')?'':'&wowzadvrplaylistduration='+duration;
//编码转换
f.src = escape(f.src);

//首先设置未安装flash时的提示
var htmlstr = "<div class='player_html5'><div style='width:100%;height:100%'><span style='font-size:18px'>您还没有安装flash播放器,请点击<a href='http://www.adobe.com/go/getflash' target='_blank'>这里</a>安装</span>/div></div>";
jq(this).css("width", w + "px");
jq(this).css("height", h + "px");
jq(this).append(htmlstr);

swfobject.embedSWF(s, i, w, h, v, null, f, p, a,fn);

swfobject.createCSS("#"+a.id, img=="none"?"background-image:none":"background-image:url("+img+")");

swfobject.addDomLoadEvent(falseToRightClick);

//取消右击事件,火狐未成功
function falseToRightClick(){
$('#'+a.id).mousedown(function(e){
if(3 == e.which){
return false;
}
})
};
//设置左击暂停...

};
})(jQuery)


页面调用时:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="scripts/jQuery-2.1.4.min.js"></script>
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/flash.js"></script>
<script type="text/javascript">
function outputStatus(e){
document.getElementById('myOutput').innerHTML = 'e.success = ' + e.success + '\ne.id = '+ e.id;
//console.log(e);
}
$(function(){
$('#myflash').video({
src:'http://192.168.134.214:1935/dvr/dvrstream.stream/manifest.f4m?DVR',
callbackfn:outputStatus,
start:20151208181100,
duration:30000
});
})
</script>
</head>
<body style='background-color:#cfcfcf;'>
<div id="movie" style='width:640px;height:360px;'>
<div id='myflash'>
</div>
</div>
<div id='myOutput'></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swfobject