Hook enum

Lifecycle hook fired by mpv during file loading and unloading.

Six phases you can intercept to lazily resolve a URL, attach per-file HTTP headers, drive a fallback path, or react to a track boundary.

Pass to Player.registerHook to subscribe; the matching MpvHookEvent arrives on PlayerStream.hook.

player.registerHook(Hook.load);
player.stream.hook.listen((event) async {
  try {
    switch (event.hook) {
      case Hook.load:
      // Redirect the URL via stream-open-filename, attach
      // file-local-options/http-header-fields, etc.
      default:
    }
  } finally {
    player.continueHook(event.id); // always, even on error
  }
});
Inheritance
Available extensions

Values

beforeStartFile → const Hook

Before any per-file work begins. Drains any pending property changes from the previous file before the new start-file event fires.

const Hook('on_before_start_file')
load → const Hook

Before a stream is opened. The most common interception point: rewrite stream-open-filename to redirect the URL, or set file-local-options/http-header-fields to attach per-file HTTP headers.

With Player.setPrefetchPlaylist on, it also runs for the next entry while the current one plays, and the playing entry gets no audio until the hook continues. In that run file-local-options still belong to the playing entry.

const Hook('on_load')
loadFail → const Hook

After a stream failed to open. Useful for fallback URLs: rewrite stream-open-filename and mpv will retry.

const Hook('on_load_fail')
preloaded → const Hook

File open, demuxer ready, but track selection and decoder init haven't run yet. Last chance to influence track choice via mpv's selection properties (aid, vid, sid).

const Hook('on_preloaded')
unload → const Hook

Before a file is closed. Cleanup hook for resources tied to the current file. Cannot resume playback from this state.

const Hook('on_unload')
afterEndFile → const Hook

After a file finished and was fully unloaded. The next file (if any) hasn't started yet.

const Hook('on_after_end_file')

Properties

hashCode → int
The hash code for this object.
no setterinherited
index → int
A numeric identifier for the enumerated value.
no setterinherited
mpvValue → String
The wire-level name mpv expects in mpv_hook_add().
final
name → String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromMpv(String raw) → Hook?
Maps an mpv-side hook name to the typed enum. Returns null for unknown values, forward-compat with future mpv builds that may add new hook phases (a warning is logged and the hook auto- continues so mpv never stalls).

Constants

values → const List<Hook>
A constant List of the values in this enum, in order of their declaration.