Skip to content

Commit

Permalink
fix dup plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Apr 22, 2024
1 parent d112d61 commit 4f8fdc1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

⚡ Oh! Another HTML5 video player.

[📕 Documentation](https://oplayer.vercel.app) | [🧡 Donate](#support) | [💜 Contributing](./CONTRIBUTING.md)
[📕 Documentation](https://oplayer.vercel.app) | [🧡 Donate](#support) | [💜 Contributing](./CONTRIBUTING.md) | [🎈 Demo](https://oplayer.vercel.app/oplayer.html?playlist=%5B%7B"title"%3A"Disney%27s+Oceans+-+MP4"%2C"src"%3A"https%3A%2F%2Fvjs.zencdn.net%2Fv%2Foceans.mp4"%2C"poster"%3A"https%3A%2F%2Fvjs.zencdn.net%2Fv%2Foceans.png"%2C"duration"%3A"00%3A46"%7D%2C%7B"title"%3A"Big+Buck+Bunny+-+HLS"%2C"src"%3A"https%3A%2F%2Ftest-streams.mux.dev%2Fx36xhzz%2Fx36xhzz.m3u8"%2C"poster"%3A"https%3A%2F%2Fd2zihajmogu5jn.cloudfront.net%2Fbig-buck-bunny%2Fbbb.png"%2C"duration"%3A"10%3A34"%7D%2C%7B"title"%3A"Big+Buck+Bunny+-+DASH"%2C"src"%3A"https%3A%2F%2Fdash.akamaized.net%2Fakamai%2Fbbb_30fps%2Fbbb_30fps.mpd"%2C"poster"%3A"https%3A%2F%2Fd2zihajmogu5jn.cloudfront.net%2Fbig-buck-bunny%2Fbbb.png"%2C"duration"%3A"10%3A34"%7D%5D&p=0)

[![npm](https://img.shields.io/npm/v/@oplayer/core?style=flat-square)](https://www.npmjs.com/package/@oplayer/core)
[![npm dt](https://img.shields.io/npm/dm/@oplayer/core?style=flat-square)](https://www.npmjs.com/package/@oplayer/core)
Expand Down Expand Up @@ -33,8 +33,6 @@
- [UPV](https://onime.netlify.app) - free anime no ads
- [Binged](https://binge.lol) - Binged - Watch Movies & TV Shows Free
- [NUSANIME](https://play.google.com/store/apps/details?id=com.nusanime.app) - Nonton Anime Sub Indo | Nonton Anime Subtitle Indonesia Gratis
- [Demo](https://oplayer.vercel.app/oplayer.html?playlist=%5B%7B"title"%3A"Disney%27s+Oceans+-+MP4"%2C"src"%3A"https%3A%2F%2Fvjs.zencdn.net%2Fv%2Foceans.mp4"%2C"poster"%3A"https%3A%2F%2Fvjs.zencdn.net%2Fv%2Foceans.png"%2C"duration"%3A"00%3A46"%7D%2C%7B"title"%3A"Big+Buck+Bunny+-+HLS"%2C"src"%3A"https%3A%2F%2Ftest-streams.mux.dev%2Fx36xhzz%2Fx36xhzz.m3u8"%2C"poster"%3A"https%3A%2F%2Fd2zihajmogu5jn.cloudfront.net%2Fbig-buck-bunny%2Fbbb.png"%2C"duration"%3A"10%3A34"%7D%2C%7B"title"%3A"Big+Buck+Bunny+-+DASH"%2C"src"%3A"https%3A%2F%2Fdash.akamaized.net%2Fakamai%2Fbbb_30fps%2Fbbb_30fps.mpd"%2C"poster"%3A"https%3A%2F%2Fd2zihajmogu5jn.cloudfront.net%2Fbig-buck-bunny%2Fbbb.png"%2C"duration"%3A"10%3A34"%7D%5D) - json demo
- [Demo2](https://oplayer.vercel.app/oplayer.html?src=https://jazzforlove.github.io/IPTV/Movie.m3u) - IPTV list
- ~~[Animex](https://www.animex.live/) - Watch Anime for free in HD quality with English subbed or dubbed.~~
- ~~[NGEWIBU.TV](https://ngewibu.tv/) - Nonton Anime Sub Indo | Nonton Anime Subtitle Indonesia Gratis~~

Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Player<Context extends Record<string, any> = Record<string, any>> {
create() {
this.render()
this.initEvent()
this.plugins.forEach(this.applyPlugin.bind(this))
this.plugins.forEach((plugin) => this.applyPlugin(plugin, true))
if (this.options.source.src) this.load(this.options.source)
Player.players.push(this)
return this
Expand Down Expand Up @@ -217,17 +217,16 @@ export class Player<Context extends Record<string, any> = Record<string, any>> {
return source
}

applyPlugin(plugin: PlayerPlugin) {
if (plugin.key && this.plugins.some((p) => p.key == plugin.key)) {
return
applyPlugin(plugin: PlayerPlugin, init = false) {
const { name, key } = plugin
if (this.context[plugin.key || plugin.name]) {
throw new Error('duplicate plugin')
}

this.plugins.push(plugin)
if (!init) this.plugins.push(plugin)
const returned = plugin.apply(this)
const { name, key } = plugin
if (returned) {
//@ts-ignore
this.context[key || name] = returned
;(this.context as any)[key || name] = returned
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/docs/public/oplayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

#oplayer [aria-label='Setting'],
.playlist,
#oplayer .playlist,
#oplayer .css-fy6n4p {
border-radius: 1rem;
background-color: rgba(0, 0, 0, 0.75);
Expand Down Expand Up @@ -169,6 +169,7 @@
#oplayer .playlist-list-item {
margin: 0 0.5rem 0.5rem;
border-radius: 0.7rem;
border: none;
}

#oplayer .playlist-head {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/src/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class PlaylistPlugin implements PlayerPlugin {
start()
})
.catch((err) => {
this.player.emit('notice', { pluginName: this.name, text: 'Playlist' + (<Error>err).message })
this.player.emit('notice', { pluginName: this.name, text: 'Playlist: ' + (<Error>err).message })
})
} else {
start()
Expand Down

0 comments on commit 4f8fdc1

Please sign in to comment.