<p dir="auto">I have 4 videos and playing first video when app starts. While playing first video, I want to initialize other three videos so that playing smoothly.  I initialized all four videos in same isolate, then sometimes UI freezes. So to avoid that I want to initialize other three videos in different isolate (not main isolate) so that UI won't freeze. I tried like so.</p>
<p dir="auto"><strong>Code:</strong></p>
<div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  VideoPlayerController _firstController;
  VideoPlayerController _secondController;
  VideoPlayerController _thirdController;
  VideoPlayerController _fourthController;
  static List&lt;VideoPlayerController&gt; _controllers;
  List&lt;String&gt; urls = [url1, url2, url3, url4];

  @override
  void initState() {
     _controllers = [
      _firstController,
      _secondController,
      _thirdController,
      _fourthController,
    ];
    _initVideo();
    _initFirstThree();
    super.initState();
  }

 _initVideo() async {
    _controllers[0] = new VideoPlayerController.network(urls[0]);
    await _controllers[0].initialize();
    await _controllers[0].setLooping(true);
    await _controllers[0].play();
    setState(() {});
  }

 _initFirstThree() async {
    for (int i = 1; i &lt; urls.length; i++) {
        await initializeVideo(i, urls[i]);
    }
  }

Future initializeVideo(int index, String url) async {
    final ReceivePort receivePort = ReceivePort();
    await Isolate.spawn(isolateInit, receivePort.sendPort);

    final SendPort sendPort = await receivePort.first;
    final VideoPlayerController result = await sendReceive(sendPort, url);

    _controllers[index] = result;
    await result.dispose(); 
  }

static isolateInit(SendPort sendPort) async {
    final ReceivePort receivePort = ReceivePort();
    sendPort.send(receivePort.sendPort);

    final msg = await receivePort.first;

      final String url = msg[0];
      final SendPort replyPort = msg[1];

      final VideoPlayerController controller = new VideoPlayerController.network(url);
      await controller.initialize();
      await controller.setLooping(true);

      replyPort.send(controller);

  }

  Future sendReceive(SendPort send, message) {
    final ReceivePort receivePort = ReceivePort();
    send.send([message, receivePort.sendPort]);
    return receivePort.first;
  }"><pre class="notranslate">  <span class="pl-c1">VideoPlayerController</span> _firstController;
  <span class="pl-c1">VideoPlayerController</span> _secondController;
  <span class="pl-c1">VideoPlayerController</span> _thirdController;
  <span class="pl-c1">VideoPlayerController</span> _fourthController;
  <span class="pl-k">static</span> <span class="pl-c1">List</span>&lt;<span class="pl-c1">VideoPlayerController</span>&gt; _controllers;
  <span class="pl-c1">List</span>&lt;<span class="pl-c1">String</span>&gt; urls <span class="pl-k">=</span> [url1, url2, url3, url4];

  <span class="pl-k">@override</span>
  <span class="pl-k">void</span> <span class="pl-en">initState</span>() {
     _controllers <span class="pl-k">=</span> [
      _firstController,
      _secondController,
      _thirdController,
      _fourthController,
    ];
    <span class="pl-en">_initVideo</span>();
    <span class="pl-en">_initFirstThree</span>();
    <span class="pl-c1">super</span>.<span class="pl-en">initState</span>();
  }

 <span class="pl-en">_initVideo</span>() <span class="pl-k">async</span> {
    _controllers[<span class="pl-c1">0</span>] <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">VideoPlayerController</span>.<span class="pl-en">network</span>(urls[<span class="pl-c1">0</span>]);
    <span class="pl-k">await</span> _controllers[<span class="pl-c1">0</span>].<span class="pl-en">initialize</span>();
    <span class="pl-k">await</span> _controllers[<span class="pl-c1">0</span>].<span class="pl-en">setLooping</span>(<span class="pl-c1">true</span>);
    <span class="pl-k">await</span> _controllers[<span class="pl-c1">0</span>].<span class="pl-en">play</span>();
    <span class="pl-en">setState</span>(() {});
  }

 <span class="pl-en">_initFirstThree</span>() <span class="pl-k">async</span> {
    <span class="pl-k">for</span> (<span class="pl-c1">int</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span>; i <span class="pl-k">&lt;</span> urls.length; i<span class="pl-k">++</span>) {
        <span class="pl-k">await</span> <span class="pl-en">initializeVideo</span>(i, urls[i]);
    }
  }

<span class="pl-c1">Future</span> <span class="pl-en">initializeVideo</span>(<span class="pl-c1">int</span> index, <span class="pl-c1">String</span> url) <span class="pl-k">async</span> {
    <span class="pl-k">final</span> <span class="pl-c1">ReceivePort</span> receivePort <span class="pl-k">=</span> <span class="pl-c1">ReceivePort</span>();
    <span class="pl-k">await</span> <span class="pl-c1">Isolate</span>.<span class="pl-en">spawn</span>(isolateInit, receivePort.sendPort);

    <span class="pl-k">final</span> <span class="pl-c1">SendPort</span> sendPort <span class="pl-k">=</span> <span class="pl-k">await</span> receivePort.first;
    <span class="pl-k">final</span> <span class="pl-c1">VideoPlayerController</span> result <span class="pl-k">=</span> <span class="pl-k">await</span> <span class="pl-en">sendReceive</span>(sendPort, url);

    _controllers[index] <span class="pl-k">=</span> result;
    <span class="pl-k">await</span> result.<span class="pl-en">dispose</span>(); 
  }

<span class="pl-k">static</span> <span class="pl-en">isolateInit</span>(<span class="pl-c1">SendPort</span> sendPort) <span class="pl-k">async</span> {
    <span class="pl-k">final</span> <span class="pl-c1">ReceivePort</span> receivePort <span class="pl-k">=</span> <span class="pl-c1">ReceivePort</span>();
    sendPort.<span class="pl-en">send</span>(receivePort.sendPort);

    <span class="pl-k">final</span> msg <span class="pl-k">=</span> <span class="pl-k">await</span> receivePort.first;

      <span class="pl-k">final</span> <span class="pl-c1">String</span> url <span class="pl-k">=</span> msg[<span class="pl-c1">0</span>];
      <span class="pl-k">final</span> <span class="pl-c1">SendPort</span> replyPort <span class="pl-k">=</span> msg[<span class="pl-c1">1</span>];

      <span class="pl-k">final</span> <span class="pl-c1">VideoPlayerController</span> controller <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">VideoPlayerController</span>.<span class="pl-en">network</span>(url);
      <span class="pl-k">await</span> controller.<span class="pl-en">initialize</span>();
      <span class="pl-k">await</span> controller.<span class="pl-en">setLooping</span>(<span class="pl-c1">true</span>);

      replyPort.<span class="pl-en">send</span>(controller);

  }

  <span class="pl-c1">Future</span> <span class="pl-en">sendReceive</span>(<span class="pl-c1">SendPort</span> send, message) {
    <span class="pl-k">final</span> <span class="pl-c1">ReceivePort</span> receivePort <span class="pl-k">=</span> <span class="pl-c1">ReceivePort</span>();
    send.<span class="pl-en">send</span>([message, receivePort.sendPort]);
    <span class="pl-k">return</span> receivePort.first;
  }</pre></div>
<p dir="auto">But after first video initialized successfully, exception says those.<br>
Is this flutter error or am I missing something?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" [VERBOSE-2:dart_isolate.cc(813)] Isolate (56689054) 'main.dart: isolateInit()' exited with an error
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
NoSuchMethodError: The method 'addObserver' was called on null.
Receiver: null
Tried calling: addObserver(Instance of '_VideoAppLifeCycleObserver')
#0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:48:5)
#1      _VideoAppLifeCycleObserver.initialize (package:video_player/video_player.dart:398:29)
#2      VideoPlayerController.initialize (package:video_player/video_player.dart:187:24)
&lt;asynchronous suspension&gt;
#3      _SwiperScreenState. isolateInit (package:komama/video_swiper.dart:115:24)
&lt;asynchronous suspension&gt;
#4      _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:292:17)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)"><pre class="notranslate"><code class="notranslate"> [VERBOSE-2:dart_isolate.cc(813)] Isolate (56689054) 'main.dart: isolateInit()' exited with an error
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
NoSuchMethodError: The method 'addObserver' was called on null.
Receiver: null
Tried calling: addObserver(Instance of '_VideoAppLifeCycleObserver')
#0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:48:5)
#1      _VideoAppLifeCycleObserver.initialize (package:video_player/video_player.dart:398:29)
#2      VideoPlayerController.initialize (package:video_player/video_player.dart:187:24)
&lt;asynchronous suspension&gt;
#3      _SwiperScreenState. isolateInit (package:komama/video_swiper.dart:115:24)
&lt;asynchronous suspension&gt;
#4      _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:292:17)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
</code></pre></div>
<p dir="auto"><strong>Flutter doctor</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[flutter] flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.13.6 17G65, locale pt-BR)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.1)
[✓] Connected devices (2 available)

! Doctor found issues in 1 category.
exit code 0"><pre class="notranslate"><code class="notranslate">[flutter] flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.13.6 17G65, locale pt-BR)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.1)
[✓] Connected devices (2 available)

! Doctor found issues in 1 category.
exit code 0
</code></pre></div>
<h2 dir="auto">Status</h2>
<p dir="auto">9/9/22: Work- in-progress</p>
<h2 dir="auto">Description</h2>
<p dir="auto">When I try to invoke a platform channel method from a custom spawned isolate, the app crashes badly (both on iOS and Android). I'm trying to figure out whether this is expected or not.</p>
<p dir="auto">If it's not, it's probably worth to mention that somewhere.</p>
<p dir="auto">Anyways I think that this can potentially be a strong limitation. Is there a way to be able to call platform plugins from a secondary isolate?</p>
<h2 dir="auto">PRs</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> iOS Engine - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1329272252" data-permission-text="Title is private" data-url="https://github.com/flutter/engine/issues/35174" data-hovercard-type="pull_request" data-hovercard-url="/flutter/engine/pull/35174/hovercard" href="https://github.com/flutter/engine/pull/35174">flutter/engine#35174</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> iOS Framework - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1329273808" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/109005" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/109005/hovercard" href="https://github.com/flutter/flutter/pull/109005">#109005</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Reland iOS Framework - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1368411373" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/111320" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/111320/hovercard" href="https://github.com/flutter/flutter/pull/111320">#111320</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Android Engine - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1356086909" data-permission-text="Title is private" data-url="https://github.com/flutter/engine/issues/35804" data-hovercard-type="pull_request" data-hovercard-url="/flutter/engine/pull/35804/hovercard" href="https://github.com/flutter/engine/pull/35804">flutter/engine#35804</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Android Framework - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1368087490" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/111279" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/111279/hovercard" href="https://github.com/flutter/flutter/pull/111279">#111279</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Add macOS platform channel integration tests - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1356187128" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/110606" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/110606/hovercard" href="https://github.com/flutter/flutter/pull/110606">#110606</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Desktop Engine - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1360597048" data-permission-text="Title is private" data-url="https://github.com/flutter/engine/issues/35893" data-hovercard-type="pull_request" data-hovercard-url="/flutter/engine/pull/35893/hovercard" href="https://github.com/flutter/engine/pull/35893">flutter/engine#35893</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Desktop Framework - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1360596034" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/110882" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/110882/hovercard" href="https://github.com/flutter/flutter/pull/110882">#110882</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Add samplecode - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1383102127" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/112235" data-hovercard-type="issue" data-hovercard-url="/flutter/flutter/issues/112235/hovercard" href="https://github.com/flutter/flutter/issues/112235">#112235</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Update website documentation - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1386862449" data-permission-text="Title is private" data-url="https://github.com/flutter/website/issues/7592" data-hovercard-type="pull_request" data-hovercard-url="/flutter/website/pull/7592/hovercard" href="https://github.com/flutter/website/pull/7592">flutter/website#7592</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Make it work with plugins that require a dart plugin registrant - <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1383132575" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/112240" data-hovercard-type="issue" data-hovercard-url="/flutter/flutter/issues/112240/hovercard" href="https://github.com/flutter/flutter/issues/112240">#112240</a></li>
</ul>