ie876下flash播放setReturnValue为空

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>html5 video</title>
</head>
<body>
<h2>2010 Ruse 360p</h2>
<div><!--每个video都需要有一个单独的parentNode,即每个video外面都有个div或者p等等。为了兼容IE876-->
	<video controls="controls" width="640" height="352" poster="cat.jpg" autoplay="autoplay">
		<source src="home.mp4" type="video/mp4" />
	</video>
</div>



<script type="text/javascript">
var config = {
	"video":{
		"type":"video/mp4"
	},
	"flash":
	{
		"player_uri":"flowplayer-3.2.7.swf",
		"need_version":"10,0,0,0",
		"autoBuffering":true,
		"html_when_no_flash":"<a target=\"_blank\" href=\"http://www.adobe.com/go/getflash\"><img height=\"39\" width=\"158\" src=\"http://www.adobe.com/images/shared/download_buttons/get_adobe_flash_player.png\" alt=\"Get Adobe Flash player\" /></a>"
	}
};
function checkFlashVersion()
{
	var flash_html = '<object id="CC" name="CC" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=need_version" width="0" height="0" data="player_uri"><param name="src" value="player_uri" /></object>';
	flash_html = flash_html.replace(/player_uri/g,config.flash.player_uri);
	flash_html = flash_html.replace(/need_version/g,config.flash.need_version);
	var div_element = document.createElement('div');
	div_element.style.width = '0';
	div_element.style.height = '0';
	div_element.innerHTML = flash_html;
	document.body.appendChild(div_element);
}
function isVideoCanPlay(video_type)
{
	var video_element = document.createElement('video');
	if(typeof(video_element.canPlayType)=='undefined')
	{
		return false;
	}
	var result = video_element.canPlayType(video_type);
	if((result=='probably')||(result=='maybe'))
	{
		return true;
	}
	return false;
}

function addFlashVideoPlayer()
{
	var source_nodes = document.getElementsByTagName('source');
	for(var i=0,l=source_nodes.length; i<l;i++)
	{
		if(source_nodes[i].type.indexOf(config.video.type)!=-1)
		{
			if(source_nodes[i].parentNode.tagName.toLowerCase()=='video')//Firefox,Chrome,IE9
			{
				var video_element = source_nodes[i].parentNode;
				var video_element_container = video_element.parentNode;
				var autoplay = video_element.autoplay;
			}
			else
			{//IE876
				var div_element = source_nodes[i].parentNode;
				var video_element = div_element.getElementsByTagName('video')[0];
				var video_element_container = div_element;
				var autoplay = typeof(video_element.autoplay)=='undefined' ? false : true;
			}
			
			var params = {

				"flashvars":"config={"playerId":"player","clip":{"url":"video_file_url"},"playlist":["poster_file_url",{"url":"video_file_url","scaling":"fit","autoPlay":autoPlay_value,"autoBuffering":autoBuffering_value}]}",
				"src":config.flash.player_uri
			};
			params.flashvars = params.flashvars.replace(/video_file_url/g,source_nodes[i].src);
			params.flashvars = params.flashvars.replace(/poster_file_url/g,video_element.poster);
			params.flashvars = params.flashvars.replace(/autoPlay_value/g,autoplay);
			params.flashvars = params.flashvars.replace(/autoBuffering_value/g,config.flash.autoBuffering);
			
			var width = video_element.width;
			var height = video_element.height;
			var attributes = {
				"data":config.flash.player_uri,
				"width":width,
				"height":height
			};
			var flash_html = createFlashObjectHTML(attributes,params);
			var div_element = document.createElement('div');
			div_element.style.width = width;
			div_element.style.height = height;
			div_element.innerHTML = flash_html;
			alert("div_element:"+flash_html);
			video_element_container.insertBefore(div_element,video_element);
			video_element.style.display = "none";
		}
	}
}
function createFlashObjectHTML(attributes,params)
{
	var flash_html = '<object id="knowledge" name="knowledge" height="attribute_height" width="attribute_width" type="application/x-shockwave-flash" data="attribute_data"><param name="flashvars" value="param_flashvars" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="quality" value="high" /><param name="cachebusting" value="false" /><param name="bgcolor" value="#000000" /><param name="src" value="param_src" />html_when_no_flash</object>';
	flash_html = flash_html.replace(/attribute_height/g,attributes.height);
	flash_html = flash_html.replace(/attribute_width/g,attributes.width);
	flash_html = flash_html.replace(/attribute_data/g,attributes.data);
	flash_html = flash_html.replace(/param_flashvars/g,params.flashvars);
	flash_html = flash_html.replace(/param_src/g,params.src);
	flash_html = flash_html.replace(/html_when_no_flash/g,config.flash.html_when_no_flash);
	return flash_html;
}

if(isVideoCanPlay(config.video.type)==false)
{
	checkFlashVersion();
	addFlashVideoPlayer();
}
</script>
</body>
</html>


 

通过以上方式实现各个浏览器播放mp4文件。 如果浏览器支持html5,用html5的video标签播放。不支持html5,用flash播放。

 

在ie876下用flash播放时,提示第一行167行报错,或者setReturnValue()参数为空。查看代码,allowScriptAccess 已经设置为“always“的情况下,仍不行。

因为activex在调用flash的各个方法时,需要flash的id和name。 若falsh的object没有id和name,则识别不出。

对以上代码的object分别添加id和name即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值