• Stars
    star
    269
  • Rank 152,662 (Top 4 %)
  • Language
    JavaScript
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔮 A web-component html5 video player facing future

eplayer logo

eplayer NPM version NPM downloads

🎯 A web-components html5 video player facing future.

who use eplayer?

eplayer.js.org - demo

clicli - C 站

Contributors

感谢大家的 pr,阿里嘎多!

Use

  1. ep 基于 web-component,为了兼容,需要事先引入 polyfill
<script src="https://unpkg.com/@webcomponents/webcomponentsjs"></script>
  1. 插入 e-player 标签,没错,只需要将平时用的 video 换成 e-player 即可
<e-player src="./001.mp4"></e-player>

type 属性可选,默认为 mp4,支持 hls 和 flv

  1. 注册 customElement,注意 type=module,使用 es6 的 import
<script type="module">
  import Eplayer from 'https://unpkg.com/eplayer?module'
  //注册 customElement
  customElements.define('e-player', Eplayer)
</script>
  1. 可选定制 css,用于穿透 shadow-dom 预留的默认样式
e-player {
  /* 主题色 默认为 clicli 同款基佬紫*/
  --theme: #00fff6;
  /* 进度条底色 一般不用设置 */
  --progress: rgba(255, 255, 255, 0.3);
  /* 进度条偏移颜色 一般不用设置 */
  --buffer: rgba(255, 255, 255, 0.6);
  /* 图标颜色 一般不用设置 */
  --icons: rgba(255, 255, 255, 0.6);
}
  1. 可选定制插件,会在右击菜单中出现一个选项,触发点击事件
Eplayer.use('github源码', ep => {
  // ep 为 shdow-root 元素
  window.location.href = 'https://github.com/132yse/eplayer'
})

hls

原生支持 mp4mkv ,如果需要支持 m3u8,需要先引入 hls.js

<script src="https://unpkg.com/hls.js"></script>

Npm

yarn add eplayer -S

同样的注册 customElement,但是注意,customElement 只能注册一次,然后还没完,往下看:

omim

omim 是腾讯前端框架 omi 的组件库分支,eplayer 已经集成进去

戳我戳我

Vue

vue 默认是不支持 web-components 的,它无法主动判断含有-的是 vue 组件还是 web 组件

所以需要手动配置,忽略掉e-player

Vue.config.ignoredElements = [
  'e-player'
]

然后,同样需要引入上面的几个文件,然后 bind 一下 src 和 type

<e-player :src="url" :type="type"></e-player>

可以封装成 vue 组件来使用:vue-web-components-wrapper

React / Fre

react 直接支持 customElement,直接在 render 函数中e-player标签

比如,下面这个 fre 的粒子

function EPlayer({ src, type }) {
  const [url, setUrl] = useState(0)
  useEffect(() => {
    fetch(`https://jx.clicli.us/jx?url=${src}@dogecloud`)
      .then(res => res.json())
      .then(data => {
        setUrl(data.url)
      })
  }, [])
  return <e-player src={url} type={type} />
}

完整代码在这里:fre-eplayer

Angular

angular.json 中添加 webcomponentsjshls.js

...
"scripts": [
  "node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js",
  "node_modules/hls.js/dist/hls.min.js"
]
...

app.component.ts 中引入 eplayer

import { Component, OnInit } from "@angular/core";
import Eplayer from "eplayer";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class AppComponent implements OnInit {
  ngOnInit(): void {
    customElements.define("e-player", Eplayer);
  }
}

在需要使用 eplayer 的模块中启用自定义元素的支持

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { CommonModule } from "@angular/common";
import { VideoComponent } from "./video.component";

@NgModule({
  declarations: [VideoComponent],
  imports: [CommonModule],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class VideoModule {}

在相应的 html 文件中对 srctype 绑定

<e-player [attr.src]="src" [attr.type]="type"></e-player>

完整项目示例: @cliclitv/pwa

ssr

ssr 服务端没有 web-components 的 API,通常 web-components 的 ssr 都会通过一些库去模拟这些 API

eplayer 不推荐这么做,请直接和正常的 html 引入方式一样,引入 cdn

WAP

WAP 端建议使用原生播放器,国产浏览器太乱了,没得兼容,同时建议往 APP 上引流

Screenshot

More Repositories

1

asta

🐙 Resumable SSR framework.
JavaScript
694
star
2

labor

Simple implementation of Web Container
Go
188
star
3

smallapp

🎃 基于 fre 的小程序架构
JavaScript
163
star
4

fard2

🎅 fre 转小程序的新思路 ♂ learn once, write anywhere.
JavaScript
114
star
5

homo

Lightweight Rendering engine similar to Harmony, but use Fre and quickjs
C
59
star
6

deku

⛄️ No-bundle Dev Server for ES modules with deno.
JavaScript
51
star
7

joke

🎃 Tiny Javascript engine, does not support Typescript (yet).
Rust
45
star
8

peacecss

Golang implement of postcss.
Go
43
star
9

soga

Tiny layout engine.
Rust
40
star
10

wxml

wxml parser rust implement
Rust
39
star
11

oplayer

👾 react native video player for expo
JavaScript
25
star
12

node_swc

swc node binding use wasm
Rust
23
star
13

venti

Simple Vue SSR framework
JavaScript
21
star
14

loki-admin

Admin app build by KokiUI
JavaScript
14
star
15

fremix

Remix for fre
JavaScript
13
star
16

gei

👾 Fast 1kb sprites system with webgl.
JavaScript
13
star
17

tinyMDE

1kb markdown 编辑器
JavaScript
12
star
18

picopack

📦 Simple Typescript library bundler.
TypeScript
11
star
19

dirty-check

reactivity system with dirty checking
JavaScript
10
star
20

bad-scroll

100 lines scroll for mobile UI
JavaScript
8
star
21

m3u8.js

🌀 m3u8 client using WebAssembly and Media Source Extension
JavaScript
8
star
22

frekit

Streaming rendering for fre SSR
6
star
23

smox-counter

A redux-like state management which based on New context api
JavaScript
5
star
24

color-picker

Auto pick the primary color.
JavaScript
5
star
25

uraban-typecho-themes

typecho themes
PHP
4
star
26

fplayer

flutter player for clicli.tv
4
star
27

bale

Zero configuration builder.
4
star
28

voe2

Concurrent rendering engine.
JavaScript
4
star
29

TinyScript

Tiny javascript engine writted by rust.
4
star
30

gan

👾 A web framework packaged Go native which use fasthttp and httprouter
Go
3
star
31

vue-ssr

A vue-ssr demo
JavaScript
3
star
32

js-parser

Coarse-grained JavaScript block parser.
3
star
33

hello_wasm

hello wasm
JavaScript
3
star
34

remix-client

JavaScript
3
star
35

voe-ide

A ide for mini programs
3
star
36

kiana

the moe plugin of kiana
JavaScript
2
star
37

fre-sortable-tree

2
star
38

1990

2
star
39

opration-task-queue

JavaScript
2
star
40

rexpr

JavaScript expression parser
2
star
41

juvenile

Simple CICD
Go
2
star
42

fre3

fre3 临时仓库
Rust
2
star
43

moe-comment

1kb severless comment system
2
star
44

varix

Remix for vue
2
star
45

immix

Create next immutable patch by mutating the current.
JavaScript
2
star
46

yisar

2
star
47

cplayer

Simple video player UI for clicli app.
2
star
48

browser-cjs

JavaScript
2
star
49

esbuild-module-federation

2
star
50

requestIdlePromise

A POC for requestIdleCallback used Promise
JavaScript
2
star
51

fre-jotal

2
star
52

easy-crypto

Easy crpto use WebAssembly
JavaScript
2
star
53

ukagaka

this is a ukagaka plugin
JavaScript
2
star
54

blockchain-cli

cli for blockchain
JavaScript
2
star
55

tiga

Faster taro alternative.
Go
2
star
56

acgzone-moblie

acgzone mobile app written by react native
2
star
57

smox-todo

todolist for react and smox
2
star
58

fre-server-component

1
star
59

xiuno

Xino is a lightweight PHP forum system.
1
star
60

fre-counter

A demo for Fre
TypeScript
1
star
61

super-element

JSX alternative with swiftUI like syntax.
1
star
62

webpack-vemix--manifest

1
star
63

typeditor

🍡 A markdown editor rewriting of typecho's
TypeScript
1
star
64

webview_video_player

Flutter video player with webview plugin.
1
star
65

jio

sm app build by react-native
1
star
66

fre-realword

A real world APP for Fre
1
star
67

UIwidgets

this is a simple slider
JavaScript
1
star
68

wean-demo-tuchong

A wean demo for tuchong.com
JavaScript
1
star
69

hvec

A simple javascript hvec_H265 muxer.
1
star
70

demon

A javascript framework for deno
1
star
71

danmu

danmuku for clicli
JavaScript
1
star
72

priority-scheduler

React scheduler implement.
1
star
73

snel

Html-first framework
JavaScript
1
star
74

js-basic-skill

js-basic-skill
1
star
75

gap

A simple and lightweight REST server framework.
1
star
76

duex

Another state manager make Redux use Vuex-like syntax
1
star
77

phpbb1

phpbb1 for php8
PHP
1
star