Home > Web Front-end > H5 Tutorial > Basic methods of embedding audio and video playback in web pages using HTML5_html5 tutorial tips

Basic methods of embedding audio and video playback in web pages using HTML5_html5 tutorial tips

WBOY
Release: 2016-05-16 15:45:52
Original
2991 people have browsed it

HTML5 features including native audio and video support without Flash.

The

HTML5

Embed a video
The following is the simplest way to embed a video file in a web page:

XML/HTML CodeCopy content to clipboard
  1. <video src="foo.mp4" width="300" height="200" controls>
  2. Your browser does not support the <video> element.
  3. video>
The current HTML5 draft specification does not specify which video formats browsers should support in the video tag. But the most commonly used video formats are:

Ogg: Ogg files with Thedora video encoder and Vorbis audio encoder.

mpeg4: MPEG4 file with H.264 video encoder and AAC audio encoder.

We can specify media files using the tag with media type and other attributes. The video element allows multiple source elements, and the browser will use the first recognized format:

XML/HTML Code
Copy content to clipboard
  1. >  
  2. <html>  
  3. <body>  
  4.    <video  width="300" height="200" controls autoplay>  
  5.        <source src="/html5/foo.ogg" type="video/ogg" />  
  6.        <source src="/html5/foo.mp4" type="video/mp4" />  
  7.        Your browser does not support the <video> element.   
  8.    video>  
  9. body>  
  10. html>  

Video 属性规范
HTML5 video 标签可以使用多个属性控制外观和感觉以及各种控制功能:

属性 描述
autoplay 如果指定这个布尔值属性,只要没有停止加载数据,视频就会立刻开始自动播放。
autobuffer 如果指定这个布尔值属性,即使没有设置自动播放,视频也会自动开始缓冲。
controls 如果指定这个属性,就允许用户控制视频播放,包括音量控制,快进,暂停或者恢复播放。
height 这个属性以 CSS 像素的形式指定视频显示区域的高度。
loop 如果指定这个布尔值属性,表示允许播放结束后自动回放。
preload 指定这个属性,视频会在载入页面时加载并准备就绪。如果指定自动播放则忽略。
poster 这是一个图像 URL,显示到用户播放或快进。
src 要嵌入的视频 URL。可选,可以在 video 块中使用 元素替代来指定要嵌入的视频。
width 这个属性以 CSS 像素的形式指定视频显示区域的宽度。

Embed audio
HTML5 supports the
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template