国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

實現簡易html視頻播放器的方法

2024-08-26 00:10:01
字體:
來源:轉載
供稿:網友

本文介紹了實現簡易html視頻播放器的方法,分享給大家,具體如下:

文件列表

root@tianshl:/data/video# lshch.mp4     test.mp4    xyx.mp4   index.html  video.list  jquery.js   

index.html

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <style type="text/css">            body{                text-align: center;            }            #content-wrap{                margin-top: 50px;                display: inline-block;            }            #content{                display: flex;            }            /* 播放器 */            #video{                display: inline-block;                margin: 0;                border: 12px solid #eee;                box-sizing: border-box;            }            .video-list-wrap{                background-color: #eee;                border-right: 1px solid #fff;            }            /* 視頻列表 */            .video-list{                display: inline-block;                box-sizing: border-box;                margin: 0;                width: 150px;                list-style: none;                padding: 0;                overflow: auto;                font-size: 12px;            }            /* 列表項 */            .video-item{                cursor: pointer;                width: 150px;                box-sizing: border-box;                text-align: left;                padding: 5px 0 5px 10px;            }            .video-item:not(:last-child){                border-bottom: 1px solid #fff;            }            .video-item:hover, .active{                background-color: #ddd;                color: #333;            }            /* 視頻列表標題 */            .video-title{                background-color: gainsboro;                font-size: 12px;                height: 30px;                line-height: 30px;                text-align: center;            }        </style>    </head>    <body>        <div id="content-wrap">            <div id="content">                <div class="video-list-wrap">                    <p class="video-title">視頻列表</p>                    <ul class="video-list"></ul>                </div>            </div>        </div>    </body>    <script type="text/javascript" src="./jquery.js"></script>    <script type="text/javascript">        $(function(){            var $content = $('#content');            // 初始化播放器            var init = function(src){                var $video = $('<video id="video" controls>');                $video.attr('preload', 'auto');                $video.attr('width', 720).attr('height', 405);                $video.attr('autoplay', 'autoplay');                $video.append($('<source>').attr('src', src).attr('type', 'video/mp4'));                $content.append($video);            };                        /* 獲取視頻列表 */            var $video_list = $('.video-list');            $video_list.css('height', 340);            $.ajax({                url: "video.list",                type: "GET",                async: true,                success: function(resp){                    $.each(resp.split('/n'), function(idx, item){                        if (item === '') return;                        var $p = $('<li>').addClass('video-item');                        $p.text(item);                        $p.data('path', item);                        $video_list.append($p);                    });                }            });            init();            /* 切換視頻 */            $video_list.on('click', '.video-item', function(){                $("#video").remove();                var $this = $(this);                $this.parent().find('.active').removeClass('active');                $this.addClass('active');                init($this.data('path'));            });        })    </script>   </html>

video.list

# 該目錄下的所有MP4文件, 供jQuery解析root@tianshl:/data/video# ls *.mp4 > video.list

nginx配置

user root;worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    sendfile        on;    keepalive_timeout  65;    server {        listen       8000;        server_name  本機IP;        location / {            # 前兩行是認證(可不加)            auth_basic "secret";            auth_basic_user_file /usr/local/nginx/passwd.db;                        # 路徑            root /data/video;            # 首頁            index index.html;        }    }}

界面展示

http://localhost:8000

認證

播放器

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 深泽县| 盱眙县| 锦屏县| 鄂州市| 饶平县| 浑源县| 驻马店市| 大理市| 左贡县| 阳泉市| 清流县| 彭阳县| 大同县| 佛山市| 怀集县| 湛江市| 义乌市| 丰城市| 武夷山市| 凌海市| 宜春市| 康马县| 夏津县| 琼结县| 霸州市| 新平| 会东县| 满城县| 通化市| 汶川县| 阿勒泰市| 侯马市| 固始县| 景德镇市| 周口市| 山丹县| 云霄县| 安塞县| 防城港市| 兴城市| 昌宁县|