Skip to content

Commit

Permalink
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/standalone/main.ts
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ const player = Player.make<Ctx>('#player', {
}
}),
torrent(),
hls({ forceHLS: true }),
hls({ forceHLS: true, defaultQuality: 1080 }),
dash(),
mpegts(),
danmaku({
@@ -105,7 +105,7 @@ const player = Player.make<Ctx>('#player', {
source: DANMAKU //SUPER_DANMAKU
}),
new Playlist({
initialIndex: 7,
initialIndex: 0,
sources: [
{
title: 'HLS with SRT subtitle',
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.26",
"version": "1.2.27-beta.0",
"description": "Hls plugin for oplayer",
"type": "module",
"main": "./dist/index.es.js",
20 changes: 18 additions & 2 deletions packages/hls/src/index.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ export interface HlsPluginOptions {

matcher?: Matcher

/**
* -1 : auto
* default auto
*/
defaultQuality?: number

/**
* custom handle hls fatal error
*/
@@ -84,7 +90,8 @@ class HlsPlugin implements PlayerPlugin {
qualityControl: true,
withBitrate: false,
qualitySwitch: 'immediate',
matcher: defaultMatcher
matcher: defaultMatcher,
defaultQuality: -1
}

constructor(options?: HlsPluginOptions) {
@@ -181,10 +188,12 @@ export default function create(options?: HlsPluginOptions): PlayerPlugin {
return new HlsPlugin(options)
}

const generateSetting = (player: Player, instance: Hls, options: HlsPluginOptions = {}) => {
const generateSetting = (player: Player, instance: Hls, options: HlsPlugin['options']) => {
const ui = player.context.ui
if (options.qualityControl) {
instance.once(HlsPlugin.library.Events.LEVEL_LOADED, () => {
let defaultSelect = options.defaultQuality

injectSetting({
icon: ui.icons.quality,
name: 'Quality',
@@ -200,6 +209,11 @@ const generateSetting = (player: Player, instance: Hls, options: HlsPluginOption
const number = useMb ? (kb / 1000).toFixed(2) : Math.floor(kb)
name += ` (${number}${useMb ? 'm' : 'k'}bps)`
}

if (level.height <= options.defaultQuality) {
defaultSelect = i
}

pre.push({ name, default: instance.currentLevel == i, value: i })
return pre
},
@@ -218,6 +232,8 @@ const generateSetting = (player: Player, instance: Hls, options: HlsPluginOption
}
}
})

if (defaultSelect != -1) instance.currentLevel = defaultSelect
})

instance.on(

0 comments on commit 91e28f3

Please sign in to comment.