swfobject简单封装

swfobject简单封装
最近一直在研究web视频播放器,找到好多可行的视频播放器,比如 JWplayer、 flowplayer、原生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 = "
您还没有安装flash播放器,请点击这里安装/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)

页面调用时:









 


你可能感兴趣的:(前端技术资料,swfobject)