用JavaScript检测视频格式支持

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用JavaScript检测视频格式支持</title>
    <script type="text/javascript">
        function checkVideo() {
            var myVideo = document.createElement('video');
            if (myVideo.canPlayType) {
                if ("" != myVideo.canPlayType('video/mp4;codecs="avc1.64001E"')) {
                    document.write("您的浏览器支持h264编码。<br>");
                }
                if ("" != myVideo.canPlayType('video/ogg; codecs="vp8"')) {
                    document.write("您的浏览器支持vp8编码。<br>");
                }
                if ("" != myVideo.canPlayType('video/ogg; codecs="theora"')) {
                    document.write("您的浏览器支持theora编码。");
                }
            }
            else {
                document.write("您的浏览器不支持要检测的视频格式。");
            }
        }
        window.onload = function () {
            checkVideo();
        }
    </script>
</head>
<body>
</body>
</html>

 

posted on 2016-02-23 17:38  周肉肉  阅读(3530)  评论(2编辑  收藏  举报

导航