Md Usama
Md Usama

Reputation: 35

Can we run Flutter Better Player preCache method in isolate?

I'm using better_player package for list of videos in my application. The package is providing the preCache method which cache the video. So just a quick question can i run this method in separate isolate so my UI thread work smoothly. Or isolates have some restrictions?

Upvotes: 0

Views: 85

Answers (1)

Sameri11
Sameri11

Reputation: 2780

There is no restrictions from dart side to use plugins inside isolates, but there is caveat described in this question and answer to it: Flutter resize and compress image in Isolate throws UnimplementedError

TLDR; you can use flutter plugins in isolates, but you should use more low-level APIs for isolates there, since it's obligatory to initiate BackgroundIsolateBinaryMessenger first.

Good news is that you don't have to use isolates at all! Reason for this: this plugin delegates caching operations to platform implementations and these implementations handle I/O and asynchronous operations itself:

  1. WorkManager used on Android, source code
  2. URLSession used on iOS and it handles non-blocking download itself internally, source code

So, you can just use preCache method in your code and not be worried about performance.

Upvotes: 0

Related Questions