bilibili/flv.js · error · InvalidArgumentException
MediaDataSource must be an javascript object!
Error message
MediaDataSource must be an javascript object!
What it means
createPlayer(mediaDataSource, optionalConfig) validates that mediaDataSource is a non-null JavaScript object before inspecting it. Passing null, undefined, a string, or a number cannot yield a usable player configuration, so an InvalidArgumentException is thrown immediately. It is a fail-fast input validation error.
Source
Thrown at src/flv.js:39
import {BaseLoader, LoaderStatus, LoaderErrors} from './io/loader.js';
import FlvPlayer from './player/flv-player.js';
import NativePlayer from './player/native-player.js';
import PlayerEvents from './player/player-events.js';
import {ErrorTypes, ErrorDetails} from './player/player-errors.js';
import LoggingControl from './utils/logging-control.js';
import {InvalidArgumentException} from './utils/exception.js';
// here are all the interfaces
// install polyfills
Polyfill.install();
// factory method
function createPlayer(mediaDataSource, optionalConfig) {
let mds = mediaDataSource;
if (mds == null || typeof mds !== 'object') {
throw new InvalidArgumentException('MediaDataSource must be an javascript object!');
}
if (!mds.hasOwnProperty('type')) {
throw new InvalidArgumentException('MediaDataSource must has type field to indicate video file type!');
}
switch (mds.type) {
case 'flv':
return new FlvPlayer(mds, optionalConfig);
default:
return new NativePlayer(mds, optionalConfig);
}
}
// feature detection
function isSupported() {
return Features.supportMSEH264Playback();View on GitHub (pinned to 42343088f2)
Solutions
- Pass a proper object: createPlayer({type:'flv', isLive:true, url:'...'})
- If the config loads asynchronously, only call createPlayer after it resolves (or in a ready/effect callback)
- Log/inspect the value right before the call to confirm it is an object
Example fix
// before
createPlayer('https://example.com/video.flv', config); // throws
// after
createPlayer({type: 'flv', isLive: true, url: 'https://example.com/video.flv'}, config); Defensive patterns
Strategy: type-guard
Validate before calling
if (mediaDataSource == null || typeof mediaDataSource !== 'object') {
throw new TypeError('mediaDataSource must be a non-null object');
} Type guard
function isMediaDataSource(v) {
return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof v.type === 'string';
} Try / catch
try {
const player = createPlayer(mediaDataSource, config);
} catch (e) {
if (e.name === 'InvalidArgumentException') {
console.error('Bad mediaDataSource, got:', typeof mediaDataSource, mediaDataSource);
} else { throw e; }
} Prevention
- Always pass an object literal {type:'flv', url:'...'}, never a raw URL string
- Await async config load before calling createPlayer
- Type the config with JSDoc/TypeScript so invalid shapes fail at compile time
- Log the value at the call site when debugging factory errors
When it happens
Trigger: Calling createPlayer(null), createPlayer(undefined), createPlayer('https://example.com/video.flv') (a URL string instead of an object), or the variable holding the config being unfilled due to a failed fetch/parse.
Common situations: Passing a plain URL string instead of {type:'flv', url:...}; async config not yet loaded when createPlayer runs; JSON.parse failure silently yielding null; typos assigning the config to a different variable.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- MediaDataSource must has type field to indicate video file t
- NativePlayer(${mediaDataSource.type}) doesn't support multip
AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01).
Data as JSON: /api/errors/70e1730a4eb7885d.
Report an issue: GitHub.