WebByteArkPlayerBackend class

Flutter Web implementation of ByteArkPlayerBackend.

Wraps a single window.bytearkPlayer instance and forwards Player controller calls to it via dart:js_interop. The JS instance itself is created by the per-playerId HtmlElementView factory once Flutter mounts the host <div> — see attachPlayer. Until then, action methods log and no-op so that calls during the brief gap between controller construction and widget mount don't throw.

Event delivery (ADR-0003). When attachPlayer runs, the backend subscribes a closure to every JS event name in WebEventTranslator.rawSubscribedEventNames. Each JS event fires the closure, which translates the name + payload into a typed ByteArkPlayerNativeEvent and hands it to the _onEvent dispatcher inside a scheduleMicrotask. The microtask wrap is load-bearing: it preserves the cross-platform async-delivery invariant so consumers can safely re-enter the controller from inside a Listener callback.

JS exception policy. Setup-time errors throw synchronously (handled by callers via the runtime guard or by bytearkPlayer(...) itself). Runtime JS exceptions from action methods are caught and routed through _onError; when the controller hasn't installed an error callback yet, errors fall through to debugPrint so they're at least visible in dev mode.

Implemented types

Constructors

WebByteArkPlayerBackend(String playerId, {void onEvent(ByteArkPlayerNativeEvent event)?, void onError(ByteArkPlayerPlaybackErrorData error)?})
Creates a backend for the Player identified by playerId.

Properties

hashCode int
The hash code for this object.
no setterinherited
playerId String
Identifier of the Player this backend drives. Matches the controller's playerId and the deterministic DOM element id used by the view factory.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

attachPlayer(ByteArkPlayerWebJs player) → void
Attaches the JS player instance once the view factory has constructed it. Called exactly once per backend; subsequent calls overwrite the reference (used when the platform view recreates after a hot reload). Also wires every JS event listener required for Listener-callback delivery, then drains any controller calls that arrived while the JS player was still being constructed.
currentPosition() Future<double?>
Returns the current playback position in seconds, or null if unavailable.
override
dispose() → void
Releases all resources held by this backend.
override
getAudios() Future<List<ByteArkPlayerMediaTrack>>
Returns the available audio tracks.
override
getAvailablePlaybackSpeeds() Future<List<double>>
Returns the available playback speeds.
override
getCurrentAudio() Future<ByteArkPlayerMediaTrack?>
Returns the currently selected audio track, if any.
override
getCurrentPlaybackSpeed() Future<double?>
Returns the current playback speed, or null if unavailable.
override
getCurrentResolution() Future<ByteArkPlayerMediaTrack?>
Returns the currently selected resolution, if any.
override
getCurrentSubtitle() Future<ByteArkPlayerMediaTrack?>
Returns the currently selected subtitle track, if any.
override
getCurrentTime() Future<int>
Returns the current playback time in seconds, or 0 if unavailable.
override
getDuration() Future<int>
Returns the total duration of the current media in seconds, or 0 if unavailable.
override
getResolutions() Future<List<ByteArkPlayerMediaTrack>>
Returns the available resolutions.
override
getSubtitles() Future<List<ByteArkPlayerMediaTrack>>
Returns the available subtitle tracks.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() → void
Pauses playback.
override
play() → void
Starts playback.
override
prepareView(ByteArkPlayerConfig config) → void
Called once by the Player widget in its initState before the embedded platform view is mounted. Implementations use this hook to perform widget-lifecycle-time setup that needs config (e.g. on Flutter Web, registering the per-playerId HtmlElementView factory). Mobile implementations no-op because PlatformView creation is handled by the native side.
override
seekBackward() → void
Seeks backward by the configured interval.
override
seekForward() → void
Seeks forward by the configured interval.
override
seekTo(int position) → void
Seeks to position in seconds.
override
setAudio(ByteArkPlayerMediaTrack track) → void
Sets the active audio track.
override
setPlaybackSpeed(double speed) → void
Sets the playback speed.
override
setResolution(ByteArkPlayerMediaTrack track) → void
Sets the active resolution.
override
setSubtitle(ByteArkPlayerMediaTrack? track) → void
Sets the active subtitle. Pass null to disable subtitles.
override
switchMediaSource(ByteArkPlayerConfig config) → void
Switches the current media source to the one described by config.
override
toggleFullScreen() → void
Toggles fullscreen mode.
override
togglePlayback() → void
Toggles between play and pause.
override
toString() String
A string representation of this object.
inherited

Operators

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