swfobject简单封装

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值