dispose method

  1. @override
Future<void> dispose({
  1. bool synchronized = true,
})
override

Disposes the Player instance & releases the resources.

Implementation

@override
Future<void> dispose({bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }
    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    await pause(synchronized: false);

    await setVideoTrack(VideoTrack.no(), synchronized: false);
    await setAudioTrack(AudioTrack.no(), synchronized: false);
    await setSubtitleTrack(SubtitleTrack.no(), synchronized: false);

    disposed = true;

    await super.dispose();

    Initializer.dispose(ctx);

    Future.delayed(const Duration(seconds: 5), () {
      mpv.mpv_terminate_destroy(ctx);
    });
  }

  if (synchronized) {
    return lock.synchronized(function);
  } else {
    return function();
  }
}