javascript插入视频类

上一篇中是利用jQuery来实现插入视频,那为什么不用js原生来写呢,这样就不加载jQuery的库了。顺便学习了javascript的面向对象实现类。

调用方式如下

[cce_js]
/**
*先实例化对象,调用对应的实例的方法
*/
var v= new video('video');
//插入youku的视频
v.youku('rCWLA1bRkUE');
//可自定义宽度和高度
v.youku('rCWLA1bRkUE',100,100);
//tudou
//v.tudou('rCWLA1bRkUE');
//ku6
//v.ku6('XXX');
//youtube
//v.youtube('XXX');
[/cce_js]

video.js源代码

[cce_js]

/**
*javascript 插入视频类
*Author:Arthur
*Blog:http://www.xbc.me
*/
function video(id){
	this.id = id;
	this.flash = '<object width="mywidth" height="myheight" type="application/x-shockwave-flash" data="myurl"><param name="quality" value="high"><param name="allowScriptAccess" value="always"><param name="flashvars" value="playMovie=true&isAutoPlay=true"></object>';
	this.youku = function(code,width,height){
		if(width == undefined){
		width = 480;
		}
	if(height == undefined){
		height =400;
		}
	var url ='http://player.youku.com/player.php/sid/myid/v.swf';
	document.getElementById(this.id).innerHTML = this.flash.replace(/myurl/,url.replace(/myid/,code)).replace(/mywidth/,width).replace(/myheight/,height);
		}
	this.tudou = function(code,width,height){
		if(width == undefined){
		width = 480;
		}
	if(height == undefined){
		height =400;
		}
	var url ='http://www.tudou.com/v/myid/v.swf';
	document.getElementById(this.id).innerHTML = this.flash.replace(/myurl/,url.replace(/myid/,code)).replace(/mywidth/,width).replace(/myheight/,height);
		}
	this.ku6 = function(code,width,height){
		if(width == undefined){
		width = 480;
		}
	if(height == undefined){
		height =400;
		}
	var url ='http://player.ku6.com/refer/myid/v.swf';
	document.getElementById(this.id).innerHTML = this.flash.replace(/myurl/,url.replace(/myid/,code)).replace(/mywidth/,width).replace(/myheight/,height);
		}
	this.youtube = function(code,width,height){
		if(width == undefined){
		width = 480;
		}
	if(height == undefined){
		height =400;
		}
	var url ='http://www.youtube.com/v/myid&hl=en_US&fs=1&autoplay=1';
	document.getElementById(this.id).innerHTML = this.flash.replace(/myurl/,url.replace(/myid/,code)).replace(/mywidth/,width).replace(/myheight/,height);
		}
}
[/cce_js]
打赏作者

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注