How to implement a simple HTML video player

How to implement a simple HTML video player

This article introduces the method of implementing a simple HTML video player and shares it with you. The details are as follows:

File List

root@tianshl:/data/video# ls
hch.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;
            }

            /* Player */
            #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 */
            .video-list{
                display: inline-block;
                box-sizing: border-box;
                margin: 0;
                width: 150px;
                list-style: none;
                padding: 0;
                overflow:auto;
                font-size: 12px;

            }

            /* List items */
            .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 list title */
            .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">Video List</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');

            // Initialize the player 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);
            };
            
            /* Get video list */
            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();

            /* Switch video */
            $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

# All MP4 files in this directory, for jQuery to parse root@tianshl:/data/video# ls *.mp4 > video.list

nginx configuration

user root;
worker_processes 1;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    sendfile on;
    keepalive_timeout 65;

    server {
        listen 8000;
        server_name local IP;
        location / {
            # The first two lines are for authentication (optional)
            auth_basic "secret";
            auth_basic_user_file /usr/local/nginx/passwd.db;
            
            # path root /data/video;
            # Home page index index.html;
        }
    }
}

Interface display

http://localhost:8000

Certification

Player

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to create a test database with tens of millions of test data in MySQL

>>:  Analysis of the difference between emits and attrs in Vue3

Recommend

Html Select option How to make the default selection

Adding the attribute selected = "selected&quo...

MySQL 5.7 deployment and remote access configuration under Linux

Preface: Recently I am going to team up with my p...

How to write HTML head in mobile device web development

Copy code The code is as follows: <head> &l...

Vue parent component calls child component function implementation

Vue parent component calls the function of the ch...

js to achieve simulated shopping mall case

Friends who are learning HTML, CSS and JS front-e...

Example of implementing GitHub's third-party authorization method in Vue

Table of contents Creating OAuth Apps Get the cod...

Gojs implements ant line animation effect

Table of contents 1. Gojs Implementation 1. Drawi...

MySQL 8.0.12 decompression version installation tutorial personal test!

Mysql8.0.12 decompression version installation me...

Box-shadow and drop-shadow to achieve irregular projection example code

When we want to add a shadow to a rectangle or ot...

A brief analysis of the difference between FIND_IN_SET() and IN in MySQL

I used the Mysql FIND_IN_SET function in a projec...

MySQL 8.0 DDL atomicity feature and implementation principle

1. Overview of DDL Atomicity Before 8.0, there wa...

Pure CSS custom multi-line ellipsis problem (from principle to implementation)

How to display text overflow? What are your needs...

MySQL 8.0.22 installation and configuration method graphic tutorial

This article records the installation and configu...

Tips for using DIV container fixed height in IE6 and IE7

There are many differences between IE6 and IE7 in ...

Implementation of single process control of Linux C background service program

introduce Usually a background server program mus...