# Simple steps to modify video player

**URL:** https://meta.discourse.org/t/video/279149
**Category:** Development
**Tags:** chinese-translation
**Created:** [September 15, 2023, 1:11pm UTC](https://meta.discourse.org/t/video/279149 "2023-09-15T13:11:03Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 15, 2023, 1:11pm UTC](https://meta.discourse.org/t/video/279149/1 "2023-09-15T13:11:03Z")

</div>

The discourse mp4 player is ugly, I was thinking about how to improve it and found this, which seems quite simple. The configuration method is also relatively simple, just need to include the css and js.

 ![image](https://global.discourse-cdn.com/meta/original/4X/e/9/8/e989579adc21815a61ea1975b2e73f71918c0755.jpeg)

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/9/b/b9bfaca59bcc39c1355c0165a5d5bdb421761b1f.jpeg)

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/3/b/f3b8e972c50be9506768a9ef0a7f08fa4cc1e653.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/e/6/fe6eca29d15f8a78566e8653741c93c68ce29846.png)

Add the js and css to the theme header

```html
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.12/plyr.css">
<script src="https://cdn.plyr.io/3.6.12/plyr.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const player = new Plyr('video');
        });
    </script>

```

Project Introduction:

[https://mp.weixin.qq.com/s?\_\_biz=MzI2MzEwNTY3OQ==&mid=2648985399&idx=1&sn=4736244185148aa38aa931d10a320e6e&chksm=f25012d7c5279bc12aa26b0864d2600330ac8da243720695240d90b003685fcff4587fe9b331&scene=27](https://mp.weixin.qq.com/s?__biz=MzI2MzEwNTY3OQ==&mid=2648985399&idx=1&sn=4736244185148aa38aa931d10a320e6e&chksm=f25012d7c5279bc12aa26b0864d2600330ac8da243720695240d90b003685fcff4587fe9b331&scene=27)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 15, 2023, 2:01pm UTC](https://meta.discourse.org/t/video/279149/2 "2023-09-15T14:01:37Z")

</div>

**English translation:** (courtesy of discourse-ai 🪄)

The MP4 player of Discourse is egregiously unappealing. In my contemplation and exploration to ameliorate it, I stumbled upon this alternative. It exudes a certain minimalistic charm, and its setup methodology is fairly straightforward. Inclusion of the respective CSS and JS does the trick.

 ![e989579adc21815a61ea1975b2e73f71918c0755_2_1035x501](https://global.discourse-cdn.com/meta/original/4X/0/0/3/003562518c8e64df884af753f1a1e57c5e62ebc3.jpeg)

 ![b9bfaca59bcc39c1355c0165a5d5bdb421761b1f_2_1035x579](https://global.discourse-cdn.com/meta/original/4X/7/6/6/766204b4a20fc043ceda1f66797ada6a27b57f75.jpeg)

 ![f3b8e972c50be9506768a9ef0a7f08fa4cc1e653_2_724x750](https://global.discourse-cdn.com/meta/original/4X/1/9/9/1992e7ecde2efe9d58b9e1e07659c4c96ebd1035.png)

Simply integrate the aforementioned JS and CSS into the header of your theme:

```plaintext
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.12/plyr.css">
<script src="https://cdn.plyr.io/3.6.12/plyr.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const player = new Plyr('video');
        });
    </script>

```

For a comprehensive introduction to the project, kindly visit:

[https://mp.weixin.qq.com/s?\_\_biz=MzI2MzEwNTY3OQ==&mid=2648985399&idx=1&sn=4736244185148aa38aa931d10a320e6e&chksm=f25012d7c5279bc12aa26b0864d2600330ac8da243720695240d90b003685fcff4587fe9b331&scene=27](https://mp.weixin.qq.com/s?__biz=MzI2MzEwNTY3OQ==&mid=2648985399&idx=1&sn=4736244185148aa38aa931d10a320e6e&chksm=f25012d7c5279bc12aa26b0864d2600330ac8da243720695240d90b003685fcff4587fe9b331&scene=27)

---

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 17, 2023, 6:51am UTC](https://meta.discourse.org/t/video/279149/3 "2023-09-17T06:51:25Z")

</div>

The content in the main text is incorrect and will cause bugs. When loading from the homepage, the player will not work. Below is what I paid $50 for someone to help me modify, shared for free with those in need. The player effect is very good and worth recommending!

Pros:  
The color tone is quite matching  
The player adapts to the screen from the beginning, rather than from small to large  
More features

To publish, just add a video tag:

```html
<video controls>
        <source src="https://xxxx/test.mp4" type="video/mp4">
    </video>

```

Add in the head, it’s best to download CSS and JS to your own CDN.

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/4/9/d49657ea3d14fefb62660d11c1216423f0eca01f.png)

```html
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.12/plyr.css">
<script src="https://cdn.openfa.net/css/plyr.js"></script>

```

Add in the main body

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/4/7/a47800c4f4068690aab0305e685955fb8e59c5db.png)

```html
<script type="text/javascript">

let curUrl = "";

setInterval(() => {
    let newUrl = location.href;
    if (curUrl !== newUrl) {
        curUrl = newUrl
        if (document.querySelector("video")) {
            new Plyr('video')
        }
    }
}, 10)

</script>

```

Final effect:

You can also set subtitle clarity, etc.

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/d/7/7d712a605c0ee2cb405f79b8b3b7f5f61e74d379.jpeg)

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [September 17, 2023, 8:05am UTC](https://meta.discourse.org/t/video/279149/4 "2023-09-17T08:05:39Z")

</div>

> [@zengyunsi](#):
>
> ```plaintext
> setInterval(() => {
> let newUrl = location.href;
> if (curUrl !== newUrl) {
> curUrl = newUrl
> if (document.querySelector("video")) {
> new Plyr('video')
> }
> }
> }, 10)
> 
> ```

???

恕我直言 这是非常糟糕的代码，糟糕透了。  
它将会每10毫秒运行一个99%的时间内都不会起作用的函数，极大的浪费性能。  
当然，家用计算机支撑得住这种花销……但它实在是太不优雅了。

IMHO this is very bad code, awful.  
It will run a function every 10 milliseconds that will not work 99% of the time, which is a huge waste of performance.  
Sure, a home computer could support the expense… but it’s just so inelegant

你应该使用discourse的API来完成这项工作。使用这个：  
You should use discourse’s API to do this. use this:

```plaintext
<script type="text/discourse-plugin" version="0.8">
api.onPageChange(() => {
        if (document.querySelector("video")) {
            new Plyr('video');
        }
});
</script>

```

> [@zengyunsi](#):
>
> 下面是我花$50请人帮我修改的

~~你应该干脆找我的（just kidding）~~

---

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 17, 2023, 8:07am UTC](https://meta.discourse.org/t/video/279149/5 "2023-09-17T08:07:58Z")

</div>

> [@Lhc\_fl](#):
>
> ```plaintext
> <script type="text/discourse-plugin" version="0.8">
> api.onPageChange(() => {
> if (document.querySelector("video")) {
> new Plyr('video');
> }
> });
> </script>
> 
> ```

How much next time I will find you, I can’t help it, I’ve been trying for a long time.

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [September 17, 2023, 8:11am UTC](https://meta.discourse.org/t/video/279149/6 "2023-09-17T08:11:01Z")

</div>

It’s fine, this is just a small gesture. We can talk about more challenging work next time.

(Of course, this doesn’t mean this job is very simple… you have to spend a lot of time reading enough discourse source code to quickly react to which API to call. And if you don’t pay, very few people will really spend time caring about what you want to achieve.)

---

<div class="post-metadata">

### Author: ![hawm](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hawm](https://meta.discourse.org/u/hawm)
#### Post date: [September 17, 2023, 8:11am UTC](https://meta.discourse.org/t/video/279149/7 "2023-09-17T08:11:17Z")

</div>

```plaintext
<script src="https://cdn.plyr.io/3.7.8/plyr.js"></script>
<script type="text/discourse-plugin" version="1.8">
  api.decorateCookedElement(elem => elem.querySelectorAll('video').forEach((e) => {new Plyr(e)}));
</script>

```

---

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 17, 2023, 8:13am UTC](https://meta.discourse.org/t/video/279149/8 "2023-09-17T08:13:22Z")

</div>

This player is really easy to use, looks a bit better than the built-in one. What tasks are you taking on, boss?

---

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 17, 2023, 8:13am UTC](https://meta.discourse.org/t/video/279149/9 "2023-09-17T08:13:46Z")

</div>

🥲 Brother, why didn’t you show up earlier?

---

<div class="post-metadata">

### Author: ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)
#### Post date: [September 17, 2023, 8:45am UTC](https://meta.discourse.org/t/video/279149/10 "2023-09-17T08:45:46Z")

</div>

I just tested and compared, and this code renders quite quickly

```plaintext
<script src="https://cdn.plyr.io/3.7.8/plyr.js"></script>
<script type="text/discourse-plugin" version="1.8">
  api.decorateCookedElement(elem => elem.querySelectorAll('video').forEach((e) => {new Plyr(e)}));
</script>

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 17, 2023, 8:46am UTC](https://meta.discourse.org/t/video/279149/11 "2023-10-17T08:46:15Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
