Menu

HTML5 TUTORIALS - HTML5 Audio & Video

HTML5 Audio & Video

ADVERTISEMENTS


<video src="foo.mp4"  width="300" height="200" controls>
    Your browser does not support the <video> element.   
</video>

ADVERTISEMENTS


<!DOCTYPE HTML>
<html>
<body>
   <video  width="300" height="200" controls autoplay>
       <source src="/html5/foo.ogg" type="video/ogg" />
       <source src="/html5/foo.mp4" type="video/mp4" />
       Your browser does not support the <video> element.
   </video>
</body>
</html>

ADVERTISEMENTS

Video Attribute Specification:

AttributeDescription
autoplayThis boolean attribute if specified, the video will automatically begin to play back as soon as it can do so without stopping to finish loading the data.
autobufferThis boolean attribute if specified, the video will automatically begin buffering even if it's not set to automatically play.
controlsIf this attribute is present, it will allow the user to control video playback, including volume, seeking, and pause/resume playback.
heightThis attribut specifies the height of the video's display area, in CSS pixels.
loopThis boolean attribute if specified, will allow video automatically seek back to the start after reaching at the end.
preloadThis attribute specifies that the video will be loaded at page load, and ready to run. Ignored if autoplay is present.
posterThis is a URL of an image to show until the user plays or seeks.
srcThe URL of the video to embed. This is optional; you may instead use the <source> element within the video block to specify the video to embed
widthThis attribut specifies the width of the video's display area, in CSS pixels.


<audio src="foo.wav" controls autoplay>
    Your browser does not support the <audio> element.   
</audio>


<!DOCTYPE HTML>
<html>
<body>
   <audio controls autoplay>
       <source src="/html5/audio.ogg" type="audio/ogg" />
       <source src="/html5/audio.wav" type="audio/wav" />
       Your browser does not support the <audio> element.
   </audio>
</body>
</html>

Audio Attribute Specification:

AttributeDescription
autoplayThis boolean attribute if specified, the audio will automatically begin to play back as soon as it can do so without stopping to finish loading the data.
autobufferThis boolean attribute if specified, the audio will automatically begin buffering even if it's not set to automatically play.
controlsIf this attribute is present, it will allow the user to control audio playback, including volume, seeking, and pause/resume playback.
loopThis boolean attribute if specified, will allow audio automatically seek back to the start after reaching at the end.
preloadThis attribute specifies that the audio will be loaded at page load, and ready to run. Ignored if autoplay is present.
srcThe URL of the audio to embed. This is optional; you may instead use the <source> element within the video block to specify the video to embed

EventDescription
abortThis event is generated when playback is aborted.
canplayThis event is generated when enough data is available that the media can be played.
endedThis event is generated when playback completes.
errorThis event is generated when an error occurs.
loadeddataThis event is generated when the first frame of the media has finished loading.
loadstartThis event is generated when loading of the media begins.
pauseThis event is generated when playback is paused.
playThis event is generated when playback starts or resumes.
progressThis event is generated periodically to inform the progress of the downloading the media.
ratechangeThis event is generated when the playback speed changes.
seekedThis event is generated when a seek operation completes.
seekingThis event is generated when a seek operation begins.
suspendThis event is generated when loading of the media is suspended.
volumechangeThis event is generated when the audio volume changes.
waitingThis event is generated when the requested operation (such as playback) is delayed pending the completion of another operation (such as a seek).


<!DOCTYPE HTML>
<head>
<script type="text/javascript">
function PlayVideo(){
   var v = document.getElementsByTagName("video")[0];  
   v.play(); 
}
</script>
</head>
<html>
<body>
   <form>
   <video  width="300" height="200" src="/html5/foo.mp4">
       Your browser does not support the <video> element.
   </video>
   <input type="button" onclick="PlayVideo();"  value="Play"/>
   </form>
</body>
</html>


AddType audio/ogg .oga
AddType audio/wav .wav
AddType video/ogg .ogv .ogg
AddType video/mp4 .mp4