diff --git a/fixtures/hlsjs/index.html b/fixtures/hlsjs/index.html new file mode 100644 index 00000000..4978aaa6 --- /dev/null +++ b/fixtures/hlsjs/index.html @@ -0,0 +1,36 @@ + + + + + + + + HLS.js 测试 + + + + +
+
+
+ +
+
+

日志

+ +
+
+
+

事件

+
+
+
+

错误

+
+
+
+
+ + + + diff --git a/fixtures/hlsjs/index.js b/fixtures/hlsjs/index.js new file mode 100644 index 00000000..239c0e43 --- /dev/null +++ b/fixtures/hlsjs/index.js @@ -0,0 +1,155 @@ +import Player from '../../packages/xgplayer/src' +import HlsJsPlugin from '../../packages/xgplayer-hls.js/src' + +localStorage.setItem('xgd', 1) +function defaultOpt() { + return { + isLive: true, + autoplay: false, + autoplayMuted: false, + retryTimes: 3, + retryCount: 3, + retryDelay: 1000, + analyzeDuration: 5000, + loadTimeout: 10000, + bufferBehind: 10, + maxJumpDistance: 3, + maxReaderInterval: 5000, + seamlesslyReload: false + } +} +var cachedOpt = localStorage.getItem('xg:test:hlsjs:opt') +try { + cachedOpt = JSON.parse(cachedOpt) +} catch (error) { + cachedOpt = undefined +} +var opts = Object.assign( + { + url: 'http://127.0.0.1:8081/fixtures/hlsjs/video/0001-4kcountry-road.m3u8' + }, + defaultOpt(), + cachedOpt +) +var testPoint = Number(localStorage.getItem('xg:test:hlsjs:point')) + +if (isNaN(testPoint)) testPoint = 0 + +window.onload = function () { + var dlEvent = document.getElementById('event') + var dlError = document.getElementById('error') + var dlLogPause = document.getElementById('log-pause') + + function inp(d) { + return d.getElementsByTagName('input')[0] + } + + var player + + + function initPlayer() { + if (player) { + player.destroy() + setTimeout(init, 100) + } else { + init() + } + function init() { + window.player = player = new Player({ + el: document.getElementById('player'), + plugins: [HlsJsPlugin], + url: opts.url, + isLive: opts.isLive, + autoplay: opts.autoplay, + autoplayMuted: opts.autoplayMuted, + }) + dlEvent.innerHTML = '' + dlError.innerHTML = '' + + function pushEvent(name, value, container) { + container = container || dlEvent + if (container === dlEvent && dlLogPause.checked) return + console.debug('[test]', name, value) + if (container === dlEvent) { + return + } + try { + value = JSON.stringify(value) + } catch (error) {} + var record = document.createElement('div') + record.innerHTML = + '
' + + name + + ' / ' + + player.video.currentTime + + '' + + value + + '
' + container.prepend(record) + } + + player.on('loadstart', function (event) { + pushEvent('loadstart', event) + }) + player.on('loadeddata', function (event) { + pushEvent('loadeddata', event) + }) + player.on('play', function (event) { + pushEvent('play', event) + }) + player.on('pause', function (event) { + pushEvent('pause', event) + }) + player.on('ended', function (event) { + pushEvent('ended', event) + }) + player.on('autoplay_was_prevented', function (event) { + pushEvent('autoplay_was_prevented', event) + }) + player.on('playing', function (event) { + pushEvent('playing', event) + }) + player.on('seeking', function (event) { + pushEvent('seeking', event) + }) + player.on('seeked', function (event) { + pushEvent('seeked', event) + }) + player.on('waiting', function (event) { + pushEvent('waiting', event) + }) + player.on('canplay', function (event) { + pushEvent('canplay', event) + }) + player.on('durationchange', function (event) { + pushEvent('durationchange', event) + }) + player.on('ready', function (event) { + pushEvent('ready', event) + }) + player.on('complete', function (event) { + pushEvent('complete', event) + }) + player.on('urlchange', function (event) { + pushEvent('urlchange', event) + }) + player.on('destroy', function (event) { + pushEvent('destroy', event) + }) + player.on('replay', function (event) { + pushEvent('replay', event) + }) + player.on('retry', function (event) { + pushEvent('retry', event) + }) + player.on('core_event', function (event) { + pushEvent(event.eventName, event) + }) + player.on('error', function (event) { + pushEvent(event.errorType, event, dlError) + }) + } + } + + initPlayer() +} diff --git a/package.json b/package.json index 04fb13fd..ed9e3675 100755 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "libd": "node ./scripts/cli.js", "dev:xgplayer": "yarn libd dev fixtures/xgplayer", "dev:hls": "yarn libd dev fixtures/hls", + "dev:hlsjs": "yarn libd dev fixtures/hlsjs", "dev:flv": "yarn libd dev fixtures/flv", "dev:flvjs": "yarn libd dev fixtures/flvjs", "dev:mp4": "yarn libd dev fixtures/mp4", diff --git a/packages/xgplayer-hls.js/package.json b/packages/xgplayer-hls.js/package.json index e0c0dd8e..1210ec77 100755 --- a/packages/xgplayer-hls.js/package.json +++ b/packages/xgplayer-hls.js/package.json @@ -35,7 +35,7 @@ "dependencies": { "deepmerge": "2.0.1", "event-emitter": "^0.3.5", - "hls.js": "^1.0.7" + "hls.js": "^1.4.12" }, "peerDependencies": { "xgplayer": ">=3.0.0-next.0", diff --git a/packages/xgplayer-hls.js/src/index.js b/packages/xgplayer-hls.js/src/index.js index 1c6dbe3a..c3d0d5d7 100755 --- a/packages/xgplayer-hls.js/src/index.js +++ b/packages/xgplayer-hls.js/src/index.js @@ -93,7 +93,9 @@ class HlsJsPlugin extends BasePlugin { if (data.fatal) { switch (data.type) { case Hls.ErrorTypes.NETWORK_ERROR: - this.hls.startLoad() + if (!(data?.networkDetails?.status === 404)) { + this.hls.startLoad() + } break case Hls.ErrorTypes.MEDIA_ERROR: this.hls.recoverMediaError() diff --git a/yarn.lock b/yarn.lock index ccf37058..ff538230 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3636,10 +3636,10 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -hls.js@^1.0.7: - version "1.4.3" - resolved "https://registry.yarnpkg.com/hls.js/-/hls.js-1.4.3.tgz#9326a680f5905631f86344d0ae155b5ef9d1bad7" - integrity sha512-EE1MjIYDNO+ynbmCpAWfhUwQpyG8gUcKKuGDGgYgfRmW/g+inQUQ8sVVVY5WZaCxEGxDMGLbXhXGepkmDIMvdw== +hls.js@^1.4.12: + version "1.4.12" + resolved "https://bnpm.byted.org/hls.js/-/hls.js-1.4.12.tgz#2022daa29d10c662387d80a5297f8330f8ef5ee2" + integrity sha512-1RBpx2VihibzE3WE9kGoVCtrhhDWTzydzElk/kyRbEOLnb1WIE+3ZabM/L8BqKFTCL3pUy4QzhXgD1Q6Igr1JA== hosted-git-info@^2.1.4: version "2.8.9"