keepAlive method

Future<void> keepAlive()

Manually keeps the underlying native player alive beyond the lifetime of its associated view.

⚠️ Use with caution.

This method should only be used when you need the player instance to persist beyond the lifecycle of the view — for example, in advanced cases where you're managing player state manually across multiple views or routes.

In most typical scenarios, the ImpulsePlayer handles cleanup automatically when the view is disposed. Using this method bypasses that behavior and may lead to memory leaks or unintended playback behavior if not managed correctly.

Note: This API is likely to be removed in a future version, once full media control lifecycle management is implemented in the plugin.

Implementation

Future<void> keepAlive() async {
  final id = await ImpulsePlayerFactory.getViewId(this);
  return ImpulsePlayerPluginPlatform.instance.keepAlive(id);
}