Skip to content

Commit

Permalink
fix: 🐛 (xgplayer-hls) 修复preferMMS未开启时,集成hls插件播放失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gemxx authored and xiyuyizhi committed Apr 24, 2024
1 parent 7163087 commit 3d82731
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions fixtures/hls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,13 @@ window.onload = function () {
setTimeout(function () {
var lastPlayback = null
var fps = 0
var prevTime = 0
setInterval(function () {
if (player && player.plugins.hls) {
var t = player.currentTime
prevTime = t
var hls = player.plugins.hls.core
if (!hls) {
return
}
var buf = hls.bufferInfo()
var pq = hls.playbackQuality()
var sp = hls.speedInfo()
Expand Down
15 changes: 9 additions & 6 deletions packages/xgplayer-hls/src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BasePlugin, Events, Errors } from 'xgplayer'
import { EVENT } from 'xgplayer-streaming-shared'
import { BasePlugin, Errors, Events } from 'xgplayer'
import { EVENT, MSE } from 'xgplayer-streaming-shared'
import { Hls } from './hls'
import { Event } from './hls/constants'
import PluginExtension from './plugin-extension'
Expand Down Expand Up @@ -55,18 +55,21 @@ export class HlsPlugin extends BasePlugin {

beforePlayerInit () {
const config = this.player.config
const hlsOpts = config.hls || {}

if (!config.url &&
// private config key
!config.__allowHlsEmptyUrl__) {
if (
(!config.url &&
// private config key
!config.__allowHlsEmptyUrl__) ||
(!hlsOpts.preferMMS && MSE.isMMSOnly())
) {
return
}

if (this.hls) this.hls.destroy()
this.player.switchURL = this._onSwitchURL
this.player.handleSource = false // disable player source handle

const hlsOpts = config.hls || {}
hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade
if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === undefined) hlsOpts.disconnectTime = 0

Expand Down
4 changes: 4 additions & 0 deletions packages/xgplayer-streaming-shared/src/mse.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export class MSE {
}
}

static isMMSOnly () {
return typeof ManagedMediaSource !== 'undefined' && typeof MediaSource === 'undefined'
}

/** @type { HTMLMediaElement | null } */
media = null

Expand Down

0 comments on commit 3d82731

Please sign in to comment.