`

html5插入mp4视频文件

阅读更多
如下所示,  全部的文件在压缩包中
具体的我也没看, 就试了一下能看视频。

<!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>video 1</h2>
<div><!--每个video都需要有一个单独的parentNode,即每个video外面都有个div或者p等等。为了兼容IE876-->
        <video controls="controls" width="640" height="352" poster="http://www.laikabase.de/cp_view/images/userfiles/slideshows/19_thumb_Shift_Image1.jpg" autoplay="autoplay">
                <source src="hunter100.mp4" type="video/mp4"></source>
        </video>
</div>
<h2>video 2</h2>
<div>
        <video controls="controls" width="500" height="500" poster="http://i782.photobucket.com/albums/yy104/stevenk0519/th_cow.jpg">
                <source src="http://i782.photobucket.com/albums/yy104/stevenk0519/cow.mp4" type="video/mp4" />
        </video>
</div>


<script type="text/javascript">
var config = {
	"video":{
		"type":"video/mp4"
	},
	"flash":
	{
		"player_uri":"http://www.happyelements.cn/wp-content/themes/happyelements/flash/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 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={&quot;playerId&quot;:&quot;player&quot;,&quot;clip&quot;:{&quot;url&quot;:&quot;video_file_url&quot;},&quot;playlist&quot;:[&quot;poster_file_url&quot;,{&quot;url&quot;:&quot;video_file_url&quot;,&quot;scaling&quot;:&quot;fit&quot;,&quot;autoPlay&quot;:autoPlay_value,&quot;autoBuffering&quot;: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;
			video_element_container.insertBefore(div_element,video_element);
			video_element.style.display = "none";
		}
	}
}
function createFlashObjectHTML(attributes,params)
{
	var flash_html = '<object 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>
分享到:
评论

相关推荐

    dede织梦编辑器中插入mp4视频文件方法 参考手册

    在使用Dede织梦系统建立网站时,有时会出现无法上传MP4视频文件的问题。为了解决这个问题,我们可以通过一系列步骤来确保MP4格式的视频文件能够被成功上传并嵌入到织梦编辑器中。 首先,需要检查Dede织梦系统的后台...

    asp.net 播放mp4视频文件代码

    总结来说,ASP.NET播放MP4视频文件涉及到HTML的`&lt;video&gt;`标签使用、IIS的MIME类型配置以及可能的CORS设置。理解并实施这些步骤,可以确保在ASP.NET应用程序中顺畅地播放MP4视频。在开发过程中,还要注意浏览器兼容性...

    mp4插入视频代码

    下面将详细介绍如何使用HTML5的`&lt;video&gt;`标签插入MP4视频,并探讨相关知识点。 1. `&lt;video&gt;`标签:这是HTML5引入的新标签,用于在网页中内联播放音频或视频。其基本语法如下: ```html &lt;video src="video.mp4" ...

    ogg小视频HTML5测试mp4视频

    Theora视频文件通常以.ogg为扩展名,这种格式在一些注重开源和版权问题的项目中比较受欢迎。 2. **mp4格式**:MP4(MPEG-4 Part 14)是一种广泛使用的数字多媒体容器格式,能够存储视频、音频、字幕和其他数据。它...

    html页面播放mp4视频

    总结来说,要在HTML页面上播放MP4视频,你需要使用`&lt;video&gt;`标签,并提供MP4视频文件的源路径。为了兼容不同的浏览器,可能还需要提供其他格式的视频源。通过JavaScript,你可以进一步控制视频的播放行为,以及...

    在Dreamweaver中插入常见格式视频

    注意,`filename`和`src`属性应替换为实际的视频文件路径。 ### 二、MPG格式视频插入 MPG(MPEG)是另一种流行的视频格式,通常用于存储压缩后的视频数据。在Dreamweaver中插入MPG视频,同样使用`&lt;object&gt;`标签,...

    向HTML中插入视频并兼容所有浏览器的方法

    然而,使用`&lt;object&gt;`标签来插入视频通常需要更多的配置,包括指定多个参数和引用额外的SWF文件(如Adobe Flash Player),这使得代码变得复杂且不易维护。 HTML5的`&lt;video&gt;`标签则是现代网页设计的标准,它提供了...

    HTML5 Player视频播放器源码API接口P2P加速支持MP4 M3U8

    对于支持的MP4格式,HTML5 Player提供了直接下载链接的功能,用户可以直接点击下载按钮获取视频文件,方便保存和离线观看。 5. **顶部悬浮条广告**: 为了实现商业变现,播放器集成了顶部悬浮条广告,这使得在不...

    给视频(mp4)增加音频轨道

    在这个场景中,我们讨论的是如何使用video.js,一个流行的HTML5视频播放器库,来给MP4视频文件增加音频轨道,并实现音频轨道之间的切换。 1. **HTML5 Video**: HTML5是现代网页的标准,它引入了内置的`&lt;video&gt;`标签...

    CKEditor 添加Video插件(MP4,MP3)并且兼容HTML5 Video插件

    CKEditor 添加Video插件(MP4)并且兼容HTML5 Video插件 1:把video文件复制到ckeditor/plugins/下面 2:ckeditor/config.js 中添加如下: a:在toolbar中['Image','Flash','Video'],配置加入“Video” 项。 b:配置 ...

    player.html-一个文件插入式视频播放器Web应用程序,用于使用通过基本目录列表提供的MP4视频文件。-JavaScript开发

    player.html-一个文件插入式视频播放器Web应用程序,用于使用通过基本目录列表提供的MP4视频文件。 player.html一个文件插入式视频播放器Web应用程序,用于使用通过基本目录列表提供的MP4视频文件。 用法player.html...

    html中插入wmv格式视频文件的代码

    在HTML中插入WMV(Windows Media Video)格式的视频文件,是通过使用`&lt;object&gt;`标签来实现的。WMV是一种由微软开发的流媒体格式,适用于在网页上播放视频内容。以下是对这段代码的详细解释: ```html classid=...

    html5实现的视频播放器

    "media"目录可能包含了一些示例视频文件,这些文件可以替换到`&lt;video&gt;`元素的`src`属性中,以便在网页上播放。 "theme"目录则可能包含了播放器的主题样式,比如皮肤颜色、按钮形状等,这些可以通过修改CSS文件来自...

    HTML5+CSS3 插入视频或音频.pdf

    然而,在 HTML5 中,可以使用 video 标签和 audio 标签来播放音频和视频文件,不需要安装插件,浏览器可以直接识别。 HTML 4 中插入视频或音频文件的缺点 在 HTML 4 中,插入视频或音频文件需要安装 Flash 插件,...

    html模板,插入音乐视频代码

    `&lt;source&gt;`标签用于指定不同格式的视频文件,以适应不同的浏览器。如果浏览器不支持`&lt;video&gt;`标签,将会显示"Your browser does not support the video tag." 的提示。 在网页设计中,模板可以极大地提高效率和一致...

    CKEditor 添加Video插件(MP4)并且兼容HTML5 Video插件,完美运行

    这个插件允许插入和编辑新的HTML5&lt;video&gt;元素。该对话框允许指定的海报图像,尺寸(他们是根据预览自动调整)和两个源文件, 这样既使用了WebM格式(Chrome浏览器,Firefox和Opera),并且只支持H264的那些浏览器...

    【dede】ckeditorckeditor-视频-MP4上传插件

    1. **文件上传**:插件会提供一个用户界面,让用户能够选择本地的MP4视频文件进行上传。这通常涉及到文件选择对话框,以及使用AJAX进行后台文件传输。 2. **服务器端处理**:上传的视频文件会被发送到服务器,...

    插入real文件插入real文件插入real文件

    HTML5的`&lt;video&gt;`标签也简化了在网页中插入和控制视频的过程。 8. **版权和合规性**:在处理任何媒体文件时,包括RealMedia,都应尊重版权法规,确保内容的合法性和合规性。如果这些文件是从互联网上下载的,务必...

    HTML5视频(MP4)播放器

    其中,`src`属性指定了视频文件的URL,`controls`属性添加了默认的播放、暂停、音量控制等基本操作。 2. **视频播放器的外观美化** 要对播放器进行自定义样式设计,可以通过CSS来改变`&lt;video&gt;`元素及其关联控件的...

Global site tag (gtag.js) - Google Analytics