Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to control the media playback using JavaScript:

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 134
    Comment on it

    While embedding a video to your webpage, very first thing you need to keep in mind is the browser support, like where this will work and where it will not. Only the latest versions of most browsers support native video playback using HTML5's "video" tag.

    Secondly, media types supported by the video tag are : mp4, webM, ogg.

    Code to embed video:

    <video width= 600  height=400 controls>
        <source src= videos/sample.mp4 type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
    </video>
    

    The control attribute is used to add controls to video like play, pause, and volume. It is advisable to include width and height attributes of the video. The type attribute of the the tag helps the browser to recognize which file it should load.

    Output:

    
    

    Once the video has been embedded into your HTML document, you can programmatically control it by using JavaScript code.

    var video1 = document.getElementByTagName(video)[0];
    video1.play();

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: