Skip to content

Commit

Permalink
fix(hls): add source tag
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed May 4, 2024
1 parent 7f333a2 commit 6e6571c
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 128 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@babel/plugin-transform-template-literals": "^7.24.1",
"@changesets/cli": "^2.27.1",
"@rollup/plugin-babel": "^6.0.4",
"@types/node": "^20.12.7",
"@types/node": "^20.12.8",
"@vitejs/plugin-react": "^4.2.1",
"babel-plugin-syntax-trailing-function-commas": "^6.22.0",
"concurrently": "^8.2.2",
Expand All @@ -57,9 +57,9 @@
"terser": "^5.31.0",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vite": "^5.2.11",
"vite-plugin-banner": "^0.7.1",
"vitest": "^1.5.3"
"vitest": "^1.6.0"
},
"pnpm": {
"patchedDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/core",
"version": "1.2.35",
"version": "1.2.36-beta.0",
"description": "Oh! Another HTML5 video player.",
"type": "module",
"main": "./dist/index.es.js",
Expand Down
22 changes: 21 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,31 @@ export type Source = {
| 'mpegts'
/** other */
| string
type?: 'string' // video/mp4 video/webm
type?: VideoMimeType | HLSMimeType | DASHMimeType
}

export type Lang = 'auto' | 'zh' | 'zh-CN' | 'en'

export type VideoMimeType =
| 'video/mp4'
| 'video/webm'
| 'video/3gp'
| 'video/ogg'
| 'video/avi'
| 'video/mpeg'
| 'video/object'

export type HLSMimeType =
| 'application/vnd.apple.mpegurl'
| 'audio/mpegurl'
| 'audio/x-mpegurl'
| 'application/x-mpegurl'
| 'video/x-mpegurl'
| 'video/mpegurl'
| 'application/mpegurl'

export type DASHMimeType = 'application/dash+xml'

export interface PlayerOptions {
source?: Source
autoplay?: boolean //https://developer.chrome.com/blog/autoplay/
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"devDependencies": {
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"sass": "^1.75.0"
"sass": "^1.76.0"
}
}
4 changes: 2 additions & 2 deletions packages/docs/public/oplayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@
<body>
<div id="oplayer"></div>

<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].35/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].36-beta.0/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].25/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].26-beta.0/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion packages/hls/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/hls",
"version": "1.2.25",
"version": "1.2.26-beta.0",
"description": "Hls plugin for oplayer",
"type": "module",
"main": "./dist/index.es.js",
Expand Down
18 changes: 15 additions & 3 deletions packages/hls/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loadSDK, type Player, type PlayerPlugin, type RequiredPartial, type Source } from '@oplayer/core'
import type Hls from 'hls.js'
import type { ErrorData, HlsConfig, LevelSwitchedData } from 'hls.js'
import type { ErrorData, HlsConfig, LevelSwitchedData, MediaAttachedData } from 'hls.js'

const PLUGIN_NAME = 'oplayer-plugin-hls'

Expand Down Expand Up @@ -141,12 +141,24 @@ class HlsPlugin implements PlayerPlugin {
active(instance, HlsPlugin.library)
}

instance.loadSource(source.src)
instance.attachMedia($video)
instance.once(HlsPlugin.library.Events.MEDIA_ATTACHED, (_, { media }: MediaAttachedData) => {
const $source = document.createElement('source') as HTMLSourceElement
$source.src = source.src
$source.type = source.type || 'application/x-mpegurl'
media.appendChild($source)

instance.once(HlsPlugin.library.Events.DESTROYING, () => {
$source.remove()
})
})

instance.on(HlsPlugin.library.Events.ERROR, function (_, data) {
errorHandler(player, data, defaultErrorHandler)
})

instance.loadSource(source.src)
instance.attachMedia($video)

if (player.context.ui?.setting) {
generateSetting(player, instance, this.options)
}
Expand Down
Loading

0 comments on commit 6e6571c

Please sign in to comment.