צעדים פשוטים לשינוי video player

סיכום מבוסס בינה מלאכותית

zengyunsi 讨论了如何修改 Discourse 的视频播放器,使其看起来更简约。zengyunsi 提供了一个例子,使用 Plyr.js 实现播放器的minimalistic 设计,并提供了相应的 CSS 和 JS 代码。

However, zengyunsi 后来发现该代码存在 bug,播放器不会在页面加载时正常生效。zengyunsi 花费 50 美元请人修改了代码,并免费分享给大家。

Lhc_fl 指出 zengyunsi 的代码存在性能问题,建议使用 Discourse 的 API 来实现播放器的功能。Lhc_fl 提供了一个使用 api.onPageChange 的例子。

hawm 提供了一个更简洁的代码示例,使用 api.decorateCookedElement 来渲染播放器。

zengyunsi 表示这个播放器确实很好用,并对 hawm 的代码表示感谢。

zengyunsi 后来测试了 hawm 的代码,并表示渲染速度更快。

总的来说,这个讨论提供了几个修改 Discourse 视频播放器的方法,包括使用 Plyr.js 和 Discourse 的 API。最终,hawm 的代码被认为是最优的解决方案。

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.

Add the js and css to the theme header

<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

English translation: (courtesy of discourse-ai :magic_wand:)

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.

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

<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

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:

<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.

<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

<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.

???

恕我直言 这是非常糟糕的代码,糟糕透了。
它将会每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:

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

你应该干脆找我的(just kidding)

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

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.)

<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>

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

:smiling_face_with_tear: Brother, why didn’t you show up earlier?

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

<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>