In previous post, we learnt about playing audio in HTML5. In this post, we shall learn about <video> that has also been introduced new in HTML5.
To create a html5 media player in web page, we can use <video>
tag.
<video src="video/VideoIntro.mp4" height="300" width="400" controls>
Video is not supported, appears only when the video tag is not supported in the browser
</video>
Following are different attributes
autoplay
– boolean - allows automatically play the video when page loadsautobuffer
- boolean - if true, video will start buffering even if autoplay
is set to false.buffered
- TimeRange - used to get the time range of the buffered mediacontrols
– display video controls like play, pause, volume etc.height
– height of the video display arealoop
– loop the playing of video when it finished playingmuted
- boolean - if true, the audio of the video will be mutedplayed
- TimeRange - used to get the time range of the played mediapreload
- can have following valuesposter
– allow image to display in place of video while video loadssrc
- the url of the video to playwidth
– width of the video play areaIn case we want to display a feedback text on the page when video is not supported, we can write the message in between <video>
tag.
Events for <video> tags are same as explained in HTML5 multimedia section here.
Output of HTML5 Video with Controls
<video src="/DemoSupportingFiles/Multimedia/VideoIntro.mp4" height="300" width="400"
controls autoplay>
Video tag is not supported
</video>
controls
attribute.<video src="/DemoSupportingFiles/Multimedia/VideoIntro.mp4" height="300" width="400"
autoplay>
Video tag is not supported
</video>
By using the <source> tag we can specify more than one source file to use by the html5 video tag. In this case, whichever file is supported by the browser, the browser starts using it to play the video.
<video height="300" width="400" autoplay>
<source src="myvideo.ogg" type="video/ogg">
<source src="myvideo.mp4" type="video/mp4">
<p>Video tag is not supported</p>
</video>
To know the html5 video format support, click here.
<video height="300" width="400" autoplay>Notice the above code snippets, where we have specified the source and after than we have also used the <object> tag to use flash media to play. Flash media will only play when the <video> tag is not supported in the end user's browser.
<source src="myvideo.ogg" type="video/ogg">
<source src="myvideo.mp4" type="video/mp4">
<object data="myplayer.swf" type="application/x-shockwave-flash">
<param value="myplayer.swf" name="movie"/>
</object>
</video>