bilibili/flv.js · error · InvalidArgumentException
NativePlayer does't support flv MediaDataSource input!
Error message
NativePlayer does't support flv MediaDataSource input!
What it means
NativePlayer handles browser-native formats (mp4, etc.) via the HTMLMediaElement directly. Its constructor throws InvalidArgumentException when mediaDataSource.type is 'flv', since FLV demuxing requires FlvPlayer, and also rejects multipart ('segments') sources. It is a format-capability guard.
Source
Thrown at src/player/native-player.js:38
import PlayerEvents from './player-events.js';
import {createDefaultConfig} from '../config.js';
import {InvalidArgumentException, IllegalStateException} from '../utils/exception.js';
// Player wrapper for browser's native player (HTMLVideoElement) without MediaSource src.
class NativePlayer {
constructor(mediaDataSource, config) {
this.TAG = 'NativePlayer';
this._type = 'NativePlayer';
this._emitter = new EventEmitter();
this._config = createDefaultConfig();
if (typeof config === 'object') {
Object.assign(this._config, config);
}
if (mediaDataSource.type.toLowerCase() === 'flv') {
throw new InvalidArgumentException('NativePlayer does\'t support flv MediaDataSource input!');
}
if (mediaDataSource.hasOwnProperty('segments')) {
throw new InvalidArgumentException(`NativePlayer(${mediaDataSource.type}) doesn't support multipart playback!`);
}
this.e = {
onvLoadedMetadata: this._onvLoadedMetadata.bind(this)
};
this._pendingSeekTime = null;
this._statisticsReporter = null;
this._mediaDataSource = mediaDataSource;
this._mediaElement = null;
}
destroy() {
if (this._mediaElement) {View on GitHub (pinned to 42343088f2)
Solutions
- Use flvjs.createPlayer(mediaDataSource) and let the factory choose: flv -> FlvPlayer, others -> NativePlayer.
- For FLV playback with FlvPlayer, set type: 'flv' and instantiate FlvPlayer.
- Remove explicit `new NativePlayer(...)` calls for FLV sources.
Example fix
// before
const player = new flvjs.NativePlayer({type: 'flv', url: 'stream.flv'});
// after
const player = flvjs.createPlayer({type: 'flv', url: 'stream.flv'}); // returns FlvPlayer Defensive patterns
Strategy: validation
Validate before calling
function createCorrectPlayer(ds) {
if (ds && typeof ds.type === 'string' && ds.type.toLowerCase() === 'flv') {
return flvjs.createPlayer(ds); // FlvPlayer
}
if (ds && Array.isArray(ds.segments)) {
throw new Error('NativePlayer does not support multipart playback');
}
return flvjs.createPlayer(ds); // NativePlayer
} Type guard
function isNativeCompatibleSource(ds) {
return !!ds && typeof ds.type === 'string' &&
ds.type.toLowerCase() !== 'flv' &&
!Object.prototype.hasOwnProperty.call(ds, 'segments');
} Try / catch
try {
player = new flvjs.NativePlayer(ds);
} catch (e) {
if (/doesn't support flv MediaDataSource/.test(e.message)) {
player = flvjs.createPlayer(ds);
} else throw e;
} Prevention
- Route all player creation through flvjs.createPlayer.
- Keep one source-of-truth config for type and never override it per player class.
- Reject 'segments' in NativePlayer configs upstream of construction.
When it happens
Trigger: new NativePlayer({type: 'flv', url: ...}) or using flvjs.createPlayer with is flv forced such that NativePlayer is selected for an flv dataSource, in the constructor (src/player/native-player.js:38).
Common situations: Explicitly instantiating NativePlayer while reusing an FLV config, a config factory that always sets type 'flv', or passing an FLV source to the wrong player class after a refactor.
Related errors
- FlvPlayer requires an flv MediaDataSource input!
- Flv: onError & onMediaInfo & onTrackMetadata & onDataAvailab
- Custom seekType specified in config but invalid customSeekHa
- Invalid seekType in config: ${config.seekType}
- Url must be a non-empty string!
AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01).
Data as JSON: /api/errors/43778977e750f320.
Report an issue: GitHub.