MovaAds class
Orchestrates pre/mid/post-roll ads on top of a IMovaApi by swapping the playing source between the content and each ad break.
Pure Dart (no Flutter dependency) so it stays unit-testable and lives in the core layer. Host-constructed and injected — call load instead of IMovaApi.open to start content with its ads. Mid-roll saves the content position and resumes there after the ad (relying on the player's parked-seek so the resume lands even before the resumed source reports a duration). Click-through is never navigated here — it is surfaced via MovaAdOpts.onAdEvent.
在 IMovaApi 之上编排前/中/后贴片广告:在正片与各广告位之间切换正在播放的源。
纯 Dart(无 Flutter 依赖),可单测并归属核心层。由宿主构造并注入——用 load 代替 IMovaApi.open 来带广告地起播正片。中插会保存正片位置并在广告后从该处续播 (依赖播放器的 seek 寄存,使续播位置在被续播源尚未报告时长前也能落地)。 点击跳转不会在此处执行——经 MovaAdOpts.onAdEvent 暴露给宿主。
与播放列表组合时使用 MovaPlaylist(api, ads: ads) 共享会话。
新代码推荐直接使用 MovaSession;本类长期保留为薄适配器。
Constructors
- MovaAds(IMovaApi api, {IMovaCutover? cutover})
-
Creates an ads orchestrator bound to
api, seeded from MovaOpts.ads.
Properties
- adPosition → Duration
-
Elapsed time into the current ad (from zero).
no setter
- canSkip → bool
-
Whether the current ad may be skipped right now.
no setter
-
changes
→ Stream<
void> -
Fires whenever the ad phase or current break changes (start/end/skip);
UI can rebuild off this in addition to the progress stream.
no setter
-
contentEnded
→ Stream<
void> -
正片及全部后贴片结束时发出一次通知;返回广播流。
MovaPlaylist(api, ads: ads)使用此信号自动连播。 示例:ads.contentEnded.listen((_) => showFinished());。no setter -
contentError
→ Stream<
Object> -
Reports resolver, content-open and terminal content failures.
no setter
- currentBreak → MovaAdBreak?
-
The ad break currently playing, or null when none is.
no setter
- debugClock ↔ DateTime Function()
-
广告时钟取时;测试注入随 fakeAsync 推进的函数,返回当前时刻。
示例:
ads.debugClock = () => origin.add(async.elapsed)。getter/setter pair - delayRemaining → Duration?
-
Time left before the pending ad takes over, or null when none is pending
or the pending break has no visible countdown.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isAdPending → bool
-
Whether an ad is counting down to take over while the content still
plays.
no setter
- isShowingAd → bool
-
Whether an ad is currently on screen.
no setter
- pendingBreak → MovaAdBreak?
-
The break that is counting down, or null when none is.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- session → MovaSession
-
返回共享会话;新代码推荐直接使用 MovaSession。
经此入口 load/jumpTo 与广告入口等价,dispose 任一入口即销毁同一会话。
示例:
await ads.session.load(source);。no setter - skipIn → Duration?
-
Time remaining until the current ad becomes skippable, or null when the
ad is not skippable at all.
no setter
Methods
-
dispose(
) → Future< void> - Releases subscriptions and closes the change stream; call once on teardown.
-
load(
MovaSource content) → Future< bool> -
Loads
contentwith its scheduled ads: plays a pre-roll first when one is configured, otherwise starts the content directly. -
loadDeferred(
MovaSourceResolver resolve) → Future< bool> - Loads content whose source is resolved lazily, with its scheduled ads.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyClicked(
) → void - Reports a click on the current ad; the host acts on MovaAdBreak.clickThroughUrl, the library does not navigate.
-
playAdNow(
MovaAdBreak ad) → Future< void> -
Immediately interrupts the content to play
adat an arbitrary point, then resumes the content where it was interrupted. For ads scheduled at runtime rather than pre-configured in MovaAdOpts.breaks; only fires while content is actually playing.adshould be a MovaAdBreakKind.mid break — its own MovaAdBreak.offset is ignored, "now" is the current content position. -
skip(
) → void - Skips the current ad if it is skippable right now; no-op otherwise.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited