Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya authored Aug 29, 2024
1 parent 78debfb commit d49f3de
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 82 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- **[AirPlay](https://oplayer.vercel.app/docs/plugins/airplay)** - cast video to apple device
- **[Playlist](https://oplayer.vercel.app/docs/plugins/playlist)** - supports playlist list ui
- **[Danmaku](https://oplayer.vercel.app/danmaku)** - biu biu biu ~
- **[Wordpress Plugin](https://github.com/shiyiya/wordpress-plugin-oplayer)** - play video easy in wordpress
- **... and much more!**

## Who use OPlayer?
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/pages/docs/guide/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ player.off('play', listener)
player.emit('cool', { msg: "It's pretty cool!" })
```

## Dynamic change video source
## Dynamic change video source / qualiry

```js
// First, create empty source player
Expand Down
53 changes: 0 additions & 53 deletions packages/docs/src/pages/docs/guide/player-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,56 +62,3 @@ export interface PlayerOptions {
isNativeUI?: () => boolean
}
```

## Methods

```ts
class Player {
on(
name: PlayerEventName | PlayerListener,
listener?: PlayerListener,
options?: {
once: boolean
}
): this
off(name: PlayerEventName, listener: PlayerListener): void
emit(name: PlayerEventName, payload?: PlayerEvent['payload']): void
setPoster(poster: string): void
play(): Promise<void> | undefined
pause(): void
togglePlay(): void | Promise<void>
mute(): void
unmute(): void
toggleMute(): void
setVolume(volume: number): void
setPlaybackRate(rate: number): void
seek(time: number): void
setLoop(loop: boolean): void
enterFullscreen(): Promise<void>
exitFullscreen(): Promise<void>
get isFullscreenEnabled(): any
get isFullScreen(): boolean
toggleFullScreen(): Promise<void>
get isPipEnabled(): boolean
enterPip(): Promise<PictureInPictureWindow>
exitPip(): false | Promise<void>
get isInPip(): boolean
togglePip(): false | Promise<void> | Promise<PictureInPictureWindow>
changeQuality(source: Omit<Source, 'poster'> | Promise<Omit<Source, 'poster'>>): Promise<void>
changeSource(source: Source | Promise<Source>, keepPlaying?: boolean): Promise<void>
destroy(): void
get isNativeUI(): boolean
get state(): number
get isPlaying(): boolean
get isMuted(): boolean
get isEnded(): boolean
get isLoop(): boolean
get isAutoPlay(): boolean
get duration(): number
get buffered(): TimeRanges
get currentTime(): number
get volume(): number
get playbackRate(): number
static get version(): string
}
```
2 changes: 1 addition & 1 deletion packages/docs/src/pages/docs/ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Install

```bash
npm i @oplayer/core @oplayer/ui
npm i @oplayer/ui
```

```html
Expand Down
71 changes: 44 additions & 27 deletions packages/hls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@
## Install

```bash
npm i @oplayer/core @oplayer/hls hls.js
npm i @oplayer/hls hls.js
```

```html
<script src="https://cdn.jsdelivr.net/npm/@oplayer/core@latest/dist/index.min.js"></script>

<!-- 1 -->
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/hls@latest/dist/index.index.js"></script>

<!-- or -->
<!-- hls + hls plugin -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@oplayer/hls@latest/dist/index.hls.js"></script> -->

<div id="oplayer" />

<script>
Expand All @@ -33,32 +26,56 @@ npm i @oplayer/core @oplayer/hls hls.js
poster: 'https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/poster.png'
}
})
.use([OHls()])
.use([OHls({ library: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/hls.min.js' })])
.create()
</script>
```

## Handle Hls.js Error
## Handle default Quality/Audio/Subtitle

```ts
OPlayer.make('#oplayer', {
source: {
src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
poster: 'https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/poster.png'
```js
OHls({
forceHLS: true, // use hls.js not native
defaultQuality(levels) {
let index = -1 // -1 => 'auto'
for (const { height, id } of levels) {
if (height <= 1080) index = id
}
return i
},
defaultAudio(tracks) {
for (const { lang, id } of object) {
if (lang == 'en' || lang.startsWith('en')) {
return id
}
}

return -1 // -1 => brower lang
},
defaultSubtitle(tracks) {
for (const { lang, id } of object) {
if (lang == 'en' || lang.startsWith('en')) {
return id
}
}

return -1 // -1 => brower lang
}
})
.use([
OHls({
errorHandler(player, data) {
// skip bufferAppendError
if (data.details == 'bufferAppendError') return
```

player.emit('error', {
...data,
message: data.type + ': ' + data.details
})
}
## Handle Hls.js Error

```ts
OHls({
errorHandler(player, data) {
// skip bufferAppendError
if (data.details == 'bufferAppendError') return

player.emit('error', {
...data,
message: data.type + ': ' + data.details
})
])
.create()
}
})
```

0 comments on commit d49f3de

Please sign in to comment.