Home  >  Article  >  Web Front-end  >  HTML5 actual combat and analysis of media elements (1. Introduction to video tags and audio tags)

HTML5 actual combat and analysis of media elements (1. Introduction to video tags and audio tags)

黄舟
黄舟Original
2017-02-13 13:26:051601browse

With the arrival of HTML5, flash cannot be supported on mobile phones. This means that music playback and video playback produced in flash can only be produced using the media tags video tag and audio tag in HTML5. Coincidentally, the mobile terminal supports the media tags video tag and audio tag in HTML5 very well. This makes HTML5 very popular on mobile devices.

The video tag and audio tag also provide very useful JavaScript APIs, allowing the creation of custom controls. The usage of the two tags is as follows.

 HTML code





When using video tags and audio tags, you must include the src attribute, pointing to the content to be loaded media files. You can also set the width and height attributes to specify the player size. Displaying an image while the video content is loading can be done by specifying the URI of the image in the poster attribute. In addition, there is a controls attribute in the tag. This attribute means that the browser should display UI controls to facilitate users to directly operate the media. Anything between the opening and closing tags is used as fallback content and is displayed if the browser does not support either media element.

Precisely because not all browsers support different media sources, multiple source tags must be written separately. A small example is as follows.

 HTML code





Browsers that support the video tag and audio tag include Firefox 3.5+ and Opera 10.5+ , IE9+, Safari 4+, Chrome, Safari for iOS and WebKit for Android.

HTML5 actual combat and analysis of media elements (1. Introduction to video tags and audio tags) has been introduced to you. Media tags are well supported in HTML5, so they are used more often. More relevant knowledge about HTML5 can be found at the Menglong website. Thank you for your support.


Newly added video playback method

JavaScript code

function bofangshipin(Num) {
            var u = navigator.userAgent;
            if (u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1) {  //苹果
                $("#vid" + Num).css("width", "100%");
                document.getElementById('vid' + Num).style.display = 'block';
                document.getElementById('vid' + Num).play();
            } else {  //安卓
            $("#vid" + Num).css({
                "width": $(".wrapperW").width(),
                "height": $(".wrapperW").height(),
                "left": ( $(".m_wraper").width() - $(".wrapperW").width() ) / 2
            });
                document.getElementById('vid' + Num).style.display = 'block';
                setTimeout(function () { document.getElementById('vid' + Num).play(); }, 1000);
            }

        }
        document.getElementById('vid' + 1).addEventListener("ended", end_playing, false);
        document.getElementById('vid' + 1).addEventListener("pause", end_playing, false);
        document.getElementById('vid' + 2).addEventListener("ended", end_playing, false);
        document.getElementById('vid' + 2).addEventListener("pause", end_playing, false);
        document.getElementById('vid' + 3).addEventListener("ended", end_playing, false);
        document.getElementById('vid' + 3).addEventListener("pause", end_playing, false);
        function end_playing() {
            document.getElementById('vid' + 1).style.display = 'none';
            document.getElementById('vid' + 2).style.display = 'none';
            document.getElementById('vid' + 3).style.display = 'none';

            $("#vid" + 1).css("width", "0%");
            $("#vid" + 2).css("width", "0%");
            $("#vid" + 3).css("width", "0%");
        }	


HTML code



The above is the content of HTML5 actual combat and analysis of media elements (1. Introduction to video tags and audio tags). For more related content, please pay attention to the PHP Chinese website (www. php.cn)!


Statement:
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