{"record":{"id":"4752c8fbfd4ba30c","repo":"bilibili/flv.js","slug":"flvplayer-load-has-been-called-please-call-unlo","errorCode":null,"errorMessage":"FlvPlayer.load() has been called, please call unload() first!","messagePattern":"FlvPlayer\\.load\\(\\) has been called, please call unload\\(\\) first!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/player/flv-player.js","lineNumber":192,"sourceCode":"            this._mediaElement.removeEventListener('loadedmetadata', this.e.onvLoadedMetadata);\n            this._mediaElement.removeEventListener('seeking', this.e.onvSeeking);\n            this._mediaElement.removeEventListener('canplay', this.e.onvCanPlay);\n            this._mediaElement.removeEventListener('stalled', this.e.onvStalled);\n            this._mediaElement.removeEventListener('progress', this.e.onvProgress);\n            this._mediaElement = null;\n        }\n        if (this._msectl) {\n            this._msectl.destroy();\n            this._msectl = null;\n        }\n    }\n\n    load() {\n        if (!this._mediaElement) {\n            throw new IllegalStateException('HTMLMediaElement must be attached before load()!');\n        }\n        if (this._transmuxer) {\n            throw new IllegalStateException('FlvPlayer.load() has been called, please call unload() first!');\n        }\n        if (this._hasPendingLoad) {\n            return;\n        }\n\n        if (this._config.deferLoadAfterSourceOpen && this._mseSourceOpened === false) {\n            this._hasPendingLoad = true;\n            return;\n        }\n\n        if (this._mediaElement.readyState > 0) {\n            this._requestSetTime = true;\n            // IE11 may throw InvalidStateError if readyState === 0\n            this._mediaElement.currentTime = 0;\n        }\n\n        this._transmuxer = new Transmuxer(this._mediaDataSource, this._config);\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/player/flv-player.js#L174-L210","documentation":"FlvPlayer.load() throws IllegalStateException if this._transmuxer already exists, meaning load() was already called and the playback pipeline is still active. The library requires unload() to tear down the transmuxer before a new load can begin, preventing two concurrent transmuxing pipelines on one player.","triggerScenarios":"Calling player.load() twice without player.unload() in between — e.g. re-invoking load on a seek/quality-switch/replay handler while the first session is still running — at src/player/flv-player.js:192.","commonSituations":"Implementing 'play again' or source-switch buttons that call load() directly, retry logic retriggering load() after an error without unloading, or load() being called both manually and via attachMediaElement flows.","solutions":["Call player.unload() before the second player.load().","To switch sources, create a fresh player: unload + detachMediaElement on the old instance, then createPlayer/attach/load again.","Guard handlers with a flag or check player._transmuxer before calling load()."],"exampleFix":"// before\nswitchButton.onclick = () => player.load();\n// after\nswitchButton.onclick = () => {\n    player.unload();\n    player.load();\n};","handlingStrategy":"try-catch","validationCode":"function reloadPlayer(player) {\n    if (player._transmuxer) player.unload();\n    player.load();\n}","typeGuard":"function canLoad(player) {\n    return !player._transmuxer;\n}","tryCatchPattern":"try {\n    player.load();\n} catch (e) {\n    if (/please call unload\\(\\) first/.test(e.message)) {\n        player.unload();\n        player.load();\n    } else throw e;\n}","preventionTips":["Pair every load() with unload() on replay/source-switch/retry paths.","Centralize playback restart in one function that always unloads first.","Debounce/lock the load trigger to prevent double invocation."],"tags":["player","lifecycle","api-misuse","state"],"backgroundTag":"player-load-already-called","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}