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={"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;
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>
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: HTML5成品MP4视频代码是基于HTML5标签 <video> 的,可以直接在网页上播放视频。相比之前的HTML版本,HTML5提供的<video>标签使用起来更加灵活和简便,支持多种媒体格式,包括MP4、WebM、Ogg等,而且还可以通过JS代码实现更多的控制和操作。 以下是HTML5成品MP4视频代码: <video controls="controls" poster="poster.jpg" preload="auto"> <source src="movie.mp4" type="video/mp4" /> <source src="movie.webm" type="video/webm" /> <source src="movie.ogv" type="video/ogg" /> Your browser does not support the video tag. </video> 其中,<video>标签表示视频的容器,controls属性表示是否显示播放器控制条,poster属性表示视频还未播放时显示的图片,preload属性表示视频是否需要预加载。 <video>标签下面是多个<source>标签,每个<source>标签表示一个视频文件,并且指定了视频文件的类型。当浏览器不支持其中一个视频文件类型时,它就会自动加载下一个<source>标签中的视频文件,直到找到支持的类型为止。 如果浏览器不支持任何一种视频格式,最后一个<source>标签中的文字 "Your browser does not support the video tag." 将会显示。 除了以上的视频源文件和文件类型之外,还可以在<video>标签中添加多种属性和事件,比如autoplay、loop、muted、onplay、onpause等,在播放过程中可以实现更多的功能和效果。 总之,HTML5成品MP4视频代码非常简单易懂,只需要用<video>和<source>标签进行基本的调用和设置即可,在网页中引入视频也就变得轻松快捷了。 ### 回答2: HTML5成品MP4视频代码非常简单。你只需要使用HTML5的<video>标签来嵌入MP4视频文件并设置一些属性即可。 首先,确保你的MP4视频文件已经准备好,并上传到网站的服务器上。 然后,将以下代码插入到你的HTML文件的<body>部分或其他合适的位置。 ```html <video controls> <source src="your-video-file.mp4" type="video/mp4"> 您的浏览器不支持HTML5视频标签。 </video> ``` 在上面的代码中,你需要将`your-video-file.mp4`替换为你的MP4视频文件的路径。 `controls`属性会自动在视频上显示一个控制条,让用户可以播放、暂停、快进、快退等等操作。 在`<source>`标签中,你需要设置视频文件的路径和MIME类型。这里我们使用`type="video/mp4"`来指定MP4视频文件的类型。 最后,在`<video>`标签的结尾添加一个友好的备用文本,以便用户的浏览器不支持HTML5视频标签时显示。 以上就是一个简单的HTML5成品MP4视频代码。你可以根据需要添加其他属性和样式来调整视频播放器的外观和功能。 ### 回答3: 下面是一个基本的HTML5视频播放器代码示例,用于嵌入MP4视频: ```html <!DOCTYPE html> <html> <head> <title>HTML5视频播放器</title> </head> <body> <video controls> <source src="video.mp4" type="video/mp4"> 您的浏览器不支持HTML5视频播放器。 </video> </body> </html> ``` 上述代码中,`<video>`标签用于嵌入视频,`controls`属性用于显示视频控制面板,`<source>`标签用于指定视频文件的源和类型。 在这个例子中,视频文件名为`video.mp4`,它应该与HTML文件位于相同的目录下。如果视频文件位于其他位置,可以在`src`属性中提供视频的完整路径。 如果您的浏览器不支持HTML5视频播放器,那么将显示`<video>`标签内的文本,这里是"您的浏览器不支持HTML5视频播放器"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值