I have dart code that opens a file as RandomAccessFile and reads from the file and stream the bytes to a video player through Http, but when the user seeks the video i need to set the position of the file to a new position and read again which throws an exception
FileSystemException: An async operation is currently pending
This is because the previous read request has not finished and i requested a new read. How can i cancel/dispose the old file read so i can read a new position?
There is no direct way to do that, but you can create your helper function for that:
Here's the class containing the helper function and using a
_cancelflag. You stop reading content once you call thecancelmethod, and the stream is closed.Here is an example:
This represents a minimal example, you can modify and adapt it for your own code.