MovaTestKernel class
A scriptable IMovaKernel (+ IMovaStatsProbe) for widget tests: records
calls and lets the test push any kernel signal, so a real Mova can
run without ever touching media_kit.
供 widget 测试使用的可编程 IMovaKernel(兼 IMovaStatsProbe):记录调用,并允许
测试推送任意内核信号,使真实的 Mova 完全不碰 media_kit 也能运行。
Example / 示例:
final k = MovaTesting.lastKernel!;
k.emitSize(1280, 720);
k.emitRestart(); // MovaState.rendered → true
- Implemented types
Constructors
-
MovaTestKernel({Object? renderHandle, bool nativeRestartAvailable = false, List<
MovaTestStep> ? script}) - Creates a test kernel.
-
MovaTestKernel.scripted({List<
MovaTestStep> script = const [MovaTestStep.ready()], Object? renderHandle}) -
Creates a ready scripted kernel using
scriptandrenderHandle. Defaults to one ready step; see the example below.
Properties
-
buffer
→ Stream<
Duration> -
Emits the buffered position (how far ahead has been downloaded)
whenever it changes.
no setter
-
buffering
→ Stream<
bool> -
Emits the current buffering state whenever it changes.
no setter
-
calls
→ List<
String> -
Names of the methods called on this kernel, in order (
open,play, ...).final -
completed
→ Stream<
bool> -
Emits
truewhen playback of the current media has completed.no setter -
duration
→ Stream<
Duration> -
Emits the total duration of the current media whenever it becomes known
or changes.
no setter
-
endFiles
→ Stream<
MovaEndFileReason> -
Fires once per
MPV_EVENT_END_FILE, carrying mpv's own termination reason. Lets the session-end state machine read the reason directly instead of inferring it fromstop()/dispose()/source-change timing (2026-09-29 update to §D3). Empty stream when unavailable.no setteroverride -
error
→ Stream<
Object> -
Emits playback errors as they occur.
no setter
- fileFormat ↔ String?
-
The demuxer reported to keepAlive, e.g.
flv(default) orhls.getter/setter pair - hasAudio ↔ bool?
-
Whether the scripted media has decodable audio: true/false, or null for
"not known yet" (the default — keepAlive then falls back to a pause).
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastPlay ↔ bool?
-
The
playflag of the most recentopen().getter/setter pair - lastSeek ↔ Duration?
-
The target of the most recent
seek().getter/setter pair - lastUri ↔ String?
-
The uri of the most recent
open().getter/setter pair -
logs
→ Stream<
MovaLogLine> -
mpv's error-level log lines, with the subsystem prefix the kernel's
errorstream throws away.no setteroverride - nativeRestartAvailable ↔ bool
-
Whether the native
MPV_EVENT_PLAYBACK_RESTARTsubscription is live right now. Whiletruethe QoE layer trusts playbackRestarts alone for TTFF and ignores the earlier-but-coarserbuffering/position fallbacks (real-device data: thebufferingedge lands ~200ms before the actual restart). Defaults tofalseso kernels without the subscription keep the fallback behavior.getter/setter pairoverride-getter - openError ↔ Object?
-
When non-null,
open()throws it (after recording the call).getter/setter pair -
playbackRestarts
→ Stream<
void> -
Fires once per
MPV_EVENT_PLAYBACK_RESTART— libmpv's own signal that "playback was reinitialized, usually at start of playback and after seeking". This is the precise, native TTFF landing signal (2026-09-29 update to §D1); kernels/platforms where subscribing to it failed silently degrade to an empty stream, and the QoE layer falls back to thebuffering-edge heuristic.no setteroverride -
playing
→ Stream<
bool> -
Emits the current playing/paused state whenever it changes.
no setter
-
position
→ Stream<
Duration> -
Emits the current playback position whenever it changes.
no setter
- renderHandle ↔ Object?
-
The underlying render handle to be attached to a video widget (e.g. a
VideoController). Its concrete type is kernel-specific and opaque to callers outside the core layer.getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
size
→ Stream<
MovaSize> -
Emits the current video frame size whenever it changes.
no setter
-
stagedSourceOptions
→ List<
Map< String, String> > -
The mpv options the player staged for each
open(), in order (an empty map when the source had none). Lets host tests assertMovaSource.mpvOptions/whepMediaTimeoutreach the kernel.final -
stalling
→ Stream<
bool> -
True exactly while playback is stopped waiting for the cache — mpv's
paused-for-cache. This is the real rebuffer signal; the kernel'sbufferingstream is media_kit's merge ofcore-idleandpaused-for-cacheand also fires on pause/seek/startup.no setteroverride
Methods
-
dispose(
) → Future< void> - Cancels scripts and closes every stream without waiting for paused listeners.
-
emitBuffer(
Duration v) → void - Pushes the buffered position.
-
emitBuffering(
bool v) → void - Pushes a buffering state.
-
emitCompleted(
bool v) → void - Pushes a completed state.
-
emitDuration(
Duration v) → void - Pushes the media duration.
-
emitEndFile(
MovaEndFileReason r) → void -
Pushes a native
END_FILEreason. -
emitError(
Object e) → void - Pushes a kernel error.
-
emitPlaying(
bool v) → void - Pushes a playing/paused state.
-
emitPosition(
Duration v) → void - Pushes a playback position.
-
emitRestart(
) → void -
Pushes a native
PLAYBACK_RESTART(lands the first frame regardless of nativeRestartAvailable). -
emitSize(
int w, int h) → void - Pushes a video frame size.
-
emitStalling(
bool v) → void -
Pushes a
paused-for-cachestate. -
enterKeepAlive(
MovaKeepAliveMode mode) → Future< bool> -
Applies
mode, saving every property it changes. Returns false (after rolling back) when a write failed or timed out. -
exitKeepAlive(
) → Future< bool> - Restores exactly what enterKeepAlive changed. Returns whether video decoding was restarted (so a fresh first frame is coming). Idempotent.
-
inspectKeepAlive(
) → Future< MovaKeepAliveMedia> - Reads the facts keepAlive decides on.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
String uri, {bool play = true}) → Future< void> - Opens a media resource by URI and optionally starts playback immediately.
-
pause(
) → Future< void> - Pauses playback.
-
play(
) → Future< void> - Starts or resumes playback.
-
sample(
) → Future< MovaStatsSnapshot?> -
One-shot sample of libmpv's counters;
nullwhen unavailable.override -
screenshot(
) → Future< Uint8List?> - Captures the current video frame as an encoded image.
-
seek(
Duration position) → Future< void> -
Seeks to the given
positionwithin the current media. -
setRate(
double rate) → Future< void> -
Sets the playback speed rate, where
1.0is normal speed. -
setVolume(
double volume) → Future< void> - Sets the playback volume.
-
stageSourceOptions(
Map< String, String> options) → void -
Stages
optionsfor the very nextopen(): that open applies them just before loading, and every later open first restores what the previous one changed — so options never leak into another source. The player calls this right before eachopen()(an empty map when the source has none). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited