Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of flv.js

Detailed explanation of the use of flv.js

php中世界最好的语言
php中世界最好的语言Original
2018-03-10 16:12:235999browse

This time I will bring you a detailed explanation of the use of flv.js, what are the precautions when using flv.js, the following is a practical case, let's take a look.

Bilibili believes that everyone is familiar with it, and Flv.js is the HTML5 Flash video (FLV) player open sourced by the bilibili website, purely native JavaScript developed (written by ECMAScript 6), no Flash is used.
Its working principle is that Flv.js parses the flv file stream in JavaScript, and encapsulates it into fmp4 in real time, and feeds it to the browser through Media Source Extensions, realizing the playback of FLV format videos.
github

If you have installed nodejs, you can use npm to install flv.js
It is recommended to use cnpm to install
Of course you can also use other methods to download
After downloading Find the flv.min.js in the dist folder and copy it out

You can use a simple server test

Code:

<!DOCTYPE html><html><head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>flv.js demo</title>
    <style>
        .mainContainer {    display: block;    width: 1024px;    margin-left: auto;    margin-right: auto;
}.urlInput {    display: block;    width: 100%;    margin-left: auto;    margin-right: auto;    margin-top: 8px;    margin-bottom: 8px;
}.centeredVideo {    display: block;    width: 100%;    height: 576px;    margin-left: auto;    margin-right: auto;    margin-bottom: auto;
}.controls {    display: block;    width: 100%;    text-align: left;    margin-left: auto;    margin-right: auto;
}    </style></head><body>
    <div class="mainContainer">
        <video id="videoElement" class="centeredVideo" controls autoplay width="1024" height="576">Your browser is too old which doesn&#39;t support HTML5 video.</video>
    </div>
    <br>
    <div class="controls">
        <!--<button onclick="flv_load()">加载</button>-->
        <button onclick="flv_start()">开始</button>
        <button onclick="flv_pause()">暂停</button>
        <button onclick="flv_destroy()">停止</button>
        <input style="width:100px" type="text" name="seekpoint" />
        <button onclick="flv_seekto()">跳转</button>
    </div>
    <script src="flv.min.js"></script>
    <script>
        var player = document.getElementById(&#39;videoElement&#39;);        if (flvjs.isSupported()) {            var flvPlayer = flvjs.createPlayer({                type: &#39;flv&#39;,                url: &#39;你的视频.flv&#39;
            });
            flvPlayer.attachMediaElement(videoElement);
            flvPlayer.load(); //加载
        }        function flv_start() {
            player.play();
        }        function flv_pause() {
            player.pause();
        }        function flv_destroy() {
            player.pause();
            player.unload();
            player.detachMediaElement();
            player.destroy();
            player = null;
        }        function flv_seekto() {
            player.currentTime = parseFloat(document.getElementsByName(&#39;seekpoint&#39;)[0].value);
        }    </script></body></html>

I believe you have read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

How to use s-xlsx to import and export Excel files

How to use JavaScript to save text data

Browser file segmented breakpoint upload

The above is the detailed content of Detailed explanation of the use of flv.js. For more information, please follow other related articles on the PHP Chinese website!

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