bilibili/flv.js · error · InvalidArgumentException

FlvPlayer requires an flv MediaDataSource input!

Error message

FlvPlayer requires an flv MediaDataSource input!

What it means

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.

Source

Thrown at src/player/flv-player.js:44

import MSEEvents from '../core/mse-events.js';
import {ErrorTypes, ErrorDetails} from './player-errors.js';
import {createDefaultConfig} from '../config.js';
import {InvalidArgumentException, IllegalStateException} from '../utils/exception.js';

class FlvPlayer {

    constructor(mediaDataSource, config) {
        this.TAG = 'FlvPlayer';
        this._type = 'FlvPlayer';
        this._emitter = new EventEmitter();

        this._config = createDefaultConfig();
        if (typeof config === 'object') {
            Object.assign(this._config, config);
        }

        if (mediaDataSource.type.toLowerCase() !== 'flv') {
            throw new InvalidArgumentException('FlvPlayer requires an flv MediaDataSource input!');
        }

        if (mediaDataSource.isLive === true) {
            this._config.isLive = true;
        }

        this.e = {
            onvLoadedMetadata: this._onvLoadedMetadata.bind(this),
            onvSeeking: this._onvSeeking.bind(this),
            onvCanPlay: this._onvCanPlay.bind(this),
            onvStalled: this._onvStalled.bind(this),
            onvProgress: this._onvProgress.bind(this)
        };

        if (self.performance && self.performance.now) {
            this._now = self.performance.now.bind(self.performance);
        } else {
            this._now = Date.now;

View on GitHub (pinned to 42343088f2)

Solutions

  1. Set mediaDataSource.type to 'flv' for FLV streams.
  2. For non-FLV media (mp4 etc.), use flvjs.createPlayer which picks NativePlayer automatically, or instantiate NativePlayer directly.
  3. Log the dataSource before constructing to catch a wrong/undefined type coming from your metadata source.

Example fix

// before
const player = new flvjs.Fl vPlayer({type: 'mp4', url: 'video.mp4'});
// after
const player = flvjs.createPlayer({type: 'mp4', url: 'video.mp4'}); // or type: 'flv' with FlvPlayer
Defensive patterns

Strategy: validation

Validate before calling

function makePlayer(mediaDataSource) {
    if (!mediaDataSource || typeof mediaDataSource.type !== 'string') {
        throw new Error('mediaDataSource.type is required');
    }
    return flvjs.createPlayer(mediaDataSource); // factory picks FlvPlayer vs NativePlayer
}

Type guard

function isFlvSource(ds) {
    return !!ds && typeof ds.type === 'string' && ds.type.toLowerCase() === 'flv';
}

Try / catch

try {
    player = new flvjs.PlayerCtor(ds);
} catch (e) {
    if (/requires an flv MediaDataSource/.test(e.message)) {
        player = flvjs.createPlayer(ds); // fall back to factory
    } else throw e;
}

Prevention

When it happens

Trigger: new FlvPlayer({type: 'mp4', url: ...}) or a type string that is not 'flv'/'FLV', in the constructor (src/player/flv-player.js:44).

Common situations: 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).

Related errors


AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01). Data as JSON: /api/errors/2984f706a78d56b8. Report an issue: GitHub.