Hongmu Notes
Home Language Notes Video streaming platform using DPlayer tutorial for playing M3U8 videos.
Language Notes PHP

Video streaming platform using DPlayer tutorial for playing M3U8 videos.

Video streaming platform using DPlayer tutorial for playing M3U8 videos.

First, load the necessary files for dplayer

css file:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.css">

js file:

<script src="https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.js"></script>

After loading the file, set up the container where the video needs to be played:

<div id="dplayer"></div>

Load js code:

<script type="text/javascript">
        let dp; // 声明 dp 变量以便在函数外访问
 
        document.addEventListener('DOMContentLoaded', function () {
            // 初始化 DPlayer 实例
            dp = new DPlayer({
                element: document.getElementById('dplayer'),
                autoplay: false,
                loop: false,
                theme: '#FADFA3',
                video: {
                    url: '视频地址',
                    type: 'hls'
                }
            });
 
            // 绑定点击事件
            $(".axis_container dd").on("click", function() {
                $(this).addClass("active").siblings().removeClass("active");
                const videoUrl = $(this).find('a').data('url'); // 获取 data-url 属性
                dp.switchVideo({
                    url: videoUrl,
                    type: 'hls'
                });
            });
        });
</script>

The html of the episode (mixed in the php code, too lazy to delete it):

<div class="axis_container clearfix">
  <dl>
    <dt>超清播放:</dt>

<?php
if($navinfor['onlinepath']){
$arr_jishu = explode(PHP_EOL,$navinfor['onlinepath']);
foreach($arr_jishu as $k => $v){
	$v1 = explode('::::::',$v);
	$active = '';
	if($k==0){
	$active = 'active';
	}
	?>
	<dd class="<?=$active?>"><a class="btn btn-orange min-100px " href="javascript:void(0);" data-url='<?=$v1[1]?>' ><?=$v1[0]?></a></dd>
	<?
}
}
?>
  </dl>
</div>
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

Responsive Fund Investment Management Website Template 1172

Responsive Fund Investment Management Website Template 1172 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the fund investment management industry, featuring a professional financial design style that effectively showcases fund products, investment strategies, management teams, and successful case studies. It helps fund management companies attract investors online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (EyouCm...
👁 61
Electronic Products Company Website Template – 11879 0554

Electronic Products Company Website Template – 11879 0554 Practical Collection Yiyou template

An EyouCMS website template designed specifically for electronics companies. Its modern, tech-driven design is ideal for showcasing electronic products, corporate brands, technical solutions, and product centers. This template helps electronics businesses showcase their brands online and attract industry-specific clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (Eyou...
👁 45
(PC+WAP) Security Service Website Template – Download Home Service Security Website Source Code – 1129

(PC+WAP) Security Service Website Template – Download Home Service Security Website Source Code – 1129 Practical Collection pbootcms Template

A security service and housekeeping security PbootCMS website template that supports PC and WAP. The design style is professional and steady, suitable for security companies and property management companies to display service content and qualifications. It helps security service companies build their brand image online and attract customers. Template display Installation instructions Website backend:/admin.php Account: admin Password: admin Unzip password: www.4s5.cn phase...
👁 58
(PC+WAP) Marketing compressor centrifugal fan website pbootcms template Red mechanical equipment website source code download 0546

(PC+WAP) Marketing compressor centrifugal fan website pbootcms template Red mechanical equipment website source code download 0546 Practical Collection pbootcms Template

A red marketing PbootCMS website template for compressors and centrifugal fans, suitable for the machinery and equipment industry, supporting PC and WAP. The design style is warm and eye-catching, which can highlight the power and technical advantages of industrial equipment. Templates help compressor or blower companies effectively display their products online and acquire potential customers. Template display Installation instructions Website backend:/admin.php Account: admin Password: admin Solution...
👁 61
Responsive Financial Planning Management Company Website Template 1173

Responsive Financial Planning Management Company Website Template 1173 Practical Collection Yiyou template

An eyouCMS responsive website template designed specifically for financial wealth management companies. Its professional financial design enables effective presentation of wealth management products, investment services, wealth management solutions, and success stories. This template helps financial institutions attract online investors and enhance brand trust. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for YououCMS | YououCMS...
👁 42
Knowledge-based paid video course website template – 28652 | 0555

Knowledge-based paid video course website template – 28652 | 0555 Practical Collection Yiyou template

This professional EyouCMS template is ideal for knowledge-based paid services and video course purchases. Its knowledge-centric design enables effective display of video courses, paid articles, membership plans, and purchase workflows, helping content creators build online knowledge-based payment platforms. Template Demo | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (Ey...
👁 60