{"record":{"id":"2984f706a78d56b8","repo":"bilibili/flv.js","slug":"flvplayer-requires-an-flv-mediadatasource-input","errorCode":null,"errorMessage":"FlvPlayer requires an flv MediaDataSource input!","messagePattern":"FlvPlayer requires an flv MediaDataSource input!","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/player/flv-player.js","lineNumber":44,"sourceCode":"import MSEEvents from '../core/mse-events.js';\nimport {ErrorTypes, ErrorDetails} from './player-errors.js';\nimport {createDefaultConfig} from '../config.js';\nimport {InvalidArgumentException, IllegalStateException} from '../utils/exception.js';\n\nclass FlvPlayer {\n\n    constructor(mediaDataSource, config) {\n        this.TAG = 'FlvPlayer';\n        this._type = 'FlvPlayer';\n        this._emitter = new EventEmitter();\n\n        this._config = createDefaultConfig();\n        if (typeof config === 'object') {\n            Object.assign(this._config, config);\n        }\n\n        if (mediaDataSource.type.toLowerCase() !== 'flv') {\n            throw new InvalidArgumentException('FlvPlayer requires an flv MediaDataSource input!');\n        }\n\n        if (mediaDataSource.isLive === true) {\n            this._config.isLive = true;\n        }\n\n        this.e = {\n            onvLoadedMetadata: this._onvLoadedMetadata.bind(this),\n            onvSeeking: this._onvSeeking.bind(this),\n            onvCanPlay: this._onvCanPlay.bind(this),\n            onvStalled: this._onvStalled.bind(this),\n            onvProgress: this._onvProgress.bind(this)\n        };\n\n        if (self.performance && self.performance.now) {\n            this._now = self.performance.now.bind(self.performance);\n        } else {\n            this._now = Date.now;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/player/flv-player.js#L26-L62","documentation":"FlvPlayer's constructor asserts that the mediaDataSource.type is 'flv' (case-insensitive). If any other type is passed, it throws InvalidArgumentException because FlvPlayer only implements the FLV demuxer. Use NativePlayer (or another player class) for non-FLV sources.","triggerScenarios":"new FlvPlayer({type: 'mp4', url: ...}) or a type string that is not 'flv'/'FLV', in the constructor (src/player/flv-player.js:44).","commonSituations":"Hardcoding FlvPlayer for a mixed-format playlist, a wrong/missing 'type' field in the mediaDataSource, or uppercase/whitespace variations (those are handled by toLowerCase, but typos like 'flvv' are not).","solutions":["Set mediaDataSource.type to 'flv' for FLV streams.","For non-FLV media (mp4 etc.), use flvjs.createPlayer which picks NativePlayer automatically, or instantiate NativePlayer directly.","Log the dataSource before constructing to catch a wrong/undefined type coming from your metadata source."],"exampleFix":"// before\nconst player = new flvjs.Fl vPlayer({type: 'mp4', url: 'video.mp4'});\n// after\nconst player = flvjs.createPlayer({type: 'mp4', url: 'video.mp4'}); // or type: 'flv' with FlvPlayer","handlingStrategy":"validation","validationCode":"function makePlayer(mediaDataSource) {\n    if (!mediaDataSource || typeof mediaDataSource.type !== 'string') {\n        throw new Error('mediaDataSource.type is required');\n    }\n    return flvjs.createPlayer(mediaDataSource); // factory picks FlvPlayer vs NativePlayer\n}","typeGuard":"function isFlvSource(ds) {\n    return !!ds && typeof ds.type === 'string' && ds.type.toLowerCase() === 'flv';\n}","tryCatchPattern":"try {\n    player = new flvjs.PlayerCtor(ds);\n} catch (e) {\n    if (/requires an flv MediaDataSource/.test(e.message)) {\n        player = flvjs.createPlayer(ds); // fall back to factory\n    } else throw e;\n}","preventionTips":["Always use flvjs.createPlayer instead of instantiating player classes directly.","Validate dataSource.type against your manifest before construction.","Never hardcode FlvPlayer for mixed-format playlists."],"tags":["player","config","argument-validation","flv"],"backgroundTag":"invalid-media-data-source","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}