Questions tagged [html5-video]

HTML5 video is an element introduced in the HTML5 draft specification for the purpose of creating a standards-compliant, plugin-free way for playing videos and movies, partially replacing the object element.

HTML5 video is an element introduced in the HTML5 draft specification for the purpose of creating a standards-compliant, plugin-free way for playing videos and movies, partially replacing the object element.

Basic usage

You can embed a video element into a HTML5 document by using the following code:

<video width="320" height="240" controls="controls">
   <source src="movie.ogg" type="video/ogg">
   <source src="movie.mp4" type="video/mp4">
   <source src="movie.webm" type="video/webm">
   <p>Your browser does not support the video tag.</p>
</video>

Attributes

The video element has the following specific attributes:

  • src gives the address of the media resource to show
  • crossorigin is a CORS settings attribute
  • postergives the address of an image file that the user agent can show while no video data is available
  • preload sets the preload behavior, valid values being none, metadata and auto
  • autoplay is a boolean attribute. When present, the user agent will automatically begin playback of the video as soon as it can do so without stopping
  • mediagroup can be used to link multiple media elements together by implicitly creating a MediaController
  • loop is a boolean attribute that, if specified, indicates that the media element is to seek back to the start of the media resource upon reaching the end
  • muted is a boolean attribute that controls the default state of the audio output of the media resource, potentially overriding user preferences
  • controls is a boolean attribute that, if present, indicates that the author has not provided a scripted controller and would like the user agent to provide its own set of controls
  • width & height specify the dimensions of the element in pixels

JavaScript API & Events

The HTML5 video element can be easily controlled from JavaScript.

For example you can easily pause and play a video by doing the following:

document.getElementsByTagName('video')[0].play();
document.getElementsByTagName('video')[0].pause();

It also has properties:

var time = document.getElementsByTagName('video')[0].currentTime; //will return the current position of the playhead

And it also fires events:

document.getElementsByTagName('video')[0].addEventListener('ended',function(){
   alert('That\'s all folks!');
},false);

For a wonderful overview refer to the demo page of the W3.

Media Encoding

Browser vendors all support different codec and container formats, so you should encode your video more than once and serve several files simultaneously to ensure your visitor will be able to watch them. A common approach (at the time of writing, i.e. spring 2012) is to serve the following:

  • Make one version that uses WebM (VP8 + Vorbis)
  • Make another version that uses H.264 baseline video and AAC “low complexity” audio in an MP4 container
  • Make another version that uses Theora video and Vorbis audio in an Ogg container

Be aware that this is CONSTANTLY CHANGING, so before you set up your video do research on what is currently supported and what the future outlook does look like!

Flash & Download Fallback

Since video is still unsupported in many browsers used (IE 7+8 for example) it should be considered a good idea to serve Flash Video as a fallback. For browsers that cannot play any video at all you can also serve a link to a simple download.

This can be done by adding the traditional object style Flash content into the fallback part of the video element:

<video controls poster="video.jpg" width="854" height="480">
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  <source src="video.ogg" type="video/ogg">
  <object type="application/x-shockwave-flash" data="player.swf" width="854" height="504">
    <param name="allowfullscreen" value="true">
    <param name="allowscriptaccess" value="always">
    <param name="flashvars" value="file=video.mp4">
    <!--[if IE]><param name="movie" value="player.swf"><![endif]-->
    <img src="video.jpg" width="854" height="480" alt="Video">
    <p>Your browser can’t play HTML5 video. <a href="video.webm"> Download it</a> instead.</p>
  </object>
</video>

FAQ (on StackOverflow)

Available libraries

There are many JavaScript libraries that offer tools to handle tasks (and fix cross-browser issues) that you will encounter when using the video-element. These are a few (if you know anything else feel free to add them):

Tools for encoding video

Further reading

Attributions & Notes

This tag-wiki was compiled with the help and contents of Dive into HTML 5, dev.opera.com, w3.org and the MDN. In case anyone has vast experience regarding HTML5 video and mobile devices I think this would be a great addition to this wiki page!

7933 questions
3
votes
3 answers

VideoJs with live stream

I am trying to get videoJs to work with a live stream I have a this link which contains an rtmp live…
Dennington-bear
  • 1,732
  • 4
  • 18
  • 44
3
votes
0 answers

iPhone prevents scrolling on html5 video element

I have a html5 video element in my website:
3
votes
1 answer

How to detect mp4 video orientation through Javascript

I'm using HTML5 video tag to link to various mp4 videos on Amazon S3 for playback. However, all the videos are played back in landscape even though some are recorded in portrait (from iOS devices). When I download the actual videos and play them…
Luke
  • 1,053
  • 2
  • 16
  • 26
3
votes
1 answer

HLS playing issues on Android 4.3 onward

What I am trying to achieve is doing live streaming via Android device. After testing, prior version 4.3, devices are playing live streamings using HLS .m3u8 properly. An example source code is as follow:
3
votes
2 answers

GET request for video files cancelled. Videos can't be found

I have a Webform that contains the following HTML:
3
votes
1 answer

Enable CORS on a WAMS media file for playback in the MPEG-DASH reference player

I've been trying to use MPEG-DASH's dash.js reference player to play media from my Windows Azure Media Services (WAMS) account. Unfortunately Chrome 33 (which supports Media Source Extensions, and thus DASH) gives me a standard CORS…
3
votes
2 answers

Sound is still playing in Background HTML 5 Video

I am playing HTML 5 Video in activity that is working fine, but when i press back button get exit from the activity and slide(Video contains by slides) but sound is still playing in background of that particular slide until it gets finish. How can i…
user3154663
  • 291
  • 1
  • 2
  • 18
3
votes
1 answer

Unable to append to source buffer

I've written a VideoBuffer class for loading segments of webm video. Each segment works separately when opened as a blob in the video element or directly in a separate browser tab, but I can't seem to get it to work when appending them to a source…
mekwall
  • 28,614
  • 6
  • 75
  • 77
3
votes
1 answer

Chrome HTML5 video with mp4/webm loaded via PHP fpassthru(): can't set currentTime?

So this is an odd issue I'm running into. I've only tested Chrome and Safari, both on Mac, and between those browsers the problem only manifests on Chrome. I have a very basic HTML5 video element, which loads a video from my server, and the user…
DanM
  • 7,037
  • 11
  • 51
  • 86
3
votes
1 answer

Code for detecting flash and html5 in android

As we know, some android devices can support flash and HTML5. However, not all android devices support HTML5. Can we have some program code like JavaScript to detect whether particular android devices support HTML5? I'm mostly interested in…
user3056561
  • 79
  • 1
  • 8
3
votes
1 answer

HTML5 Video Toggle Mute On Click?

I'm trying to toggle mute by clicking on the video. I am able to un-mute the video when clicking using this code: $(document).ready(function(){ $("video").prop('muted', true); $("video").click( function (){ if(…
user3047579
  • 33
  • 1
  • 1
  • 4
3
votes
1 answer

How to measure delay in video streaming?

I have created a video conferencing and video streaming application using webRTC. It is working perfectly fine. But how can I measure the delay in the transmitting and receiving sides. Are there any utilities for it ?
krammer
  • 2,598
  • 2
  • 25
  • 46
3
votes
0 answers

how to stop webview video running in background?

HTML5 video open in the background does not stop. I am opening the webview in a fragment. I tried following code: public void onPause(){ mWebView.onPause(); try { Class.forName("android.webkit.WebView") …
Omid Aminiva
  • 667
  • 5
  • 14
3
votes
1 answer

What JavaScript events qualify as "user-initiated" in iOS with regards to HTML5 video/audio?

It's a well known nuisance feature in iOS that events like onload won't start downloading video due to Apple's misguided brilliant "user-controlled downloads over cellular networks" policy. I'm currently working on a video player that does some…
aendra
  • 5,286
  • 3
  • 38
  • 57
3
votes
3 answers

Forwarding WebRTC Video for Peer to Peer Broadcasting

Peers must be able to forward data in order to broadcast in a peer-to-peer overlay (such as Chord). When each node (peer) receives data it will then forward the data to all other nodes in their routing table, who will then forward the same data…
JSON
  • 1,819
  • 20
  • 27
1 2 3
99
100