JideGuru / epub_viewer

An epub reader for Flutter. Wrapped around Folioreader.(WIP)
https://pub.dev/packages/epub_viewer
Apache License 2.0
146 stars 80 forks source link

Locator stream not working #82

Open ntanvinh opened 3 years ago

ntanvinh commented 3 years ago

Issue / Feature - Locator of epub file Platform (android, iOS or both) - android Crash / Error - Not work as expected

Steps to reproduce / Describe in detail - I'm copy code from example. However, this code to get locator has never been run.

EpubViewer.locatorStream.listen((locator) {
      print('LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator))}');
      // convert locator from string to json and save to your database to be retrieved later
    });

When I pressed back button, the console still show the readLocator but nothing show from the print statement: I/readLocator(29636): -> saveReadLocator -> {"bookId":"978-1-5457-4803-9","href":"/OEBPS/html/Preface.xhtml","created":1616838857610,"locations":{"cfi":"epubcfi(/0!/4/16/5:0)"},"title":""}

Please fix it or maybe I have to do something else? I'm using the latest version of the package 0.1.9.

pradeepsthapa commented 3 years ago

Same problem, location not streaming.

ameteku commented 3 years ago

I just created a pr for getting the page number for iOS but it seems no stream is ever emitted for android. This is the link to my pr: https://github.com/JideGuru/epub_viewer/pull/103

prkarthikeyan commented 3 years ago

Locator stream still seems to be an issue. Is this repo being maintained, i ended up using this, and resuming the last read page seems to be a problem for books (android). :(

amigax commented 2 years ago

yeh I cant get this to work either, it does print the locator stream when you cclose the book, but how to pass it in so we can resume reading?

pranjalpc99 commented 2 years ago

Locator Stream is working. Save the fromJson response to a variable and then access the details. final readLocator = EpubLocator.fromJson(jsonDecode(locator)); print(readLocator.href);

I am using the latest version ^0.2.4.

ghost commented 2 years ago

@pranjalpc99 your call is going into the listening part? See here is my code if you get any error into this please let me know

if (await file.exists()) {
        EpubViewer.setConfig(
          themeColor: Color(0xFFA1687C),
          identifier: 'iosBook',
          scrollDirection: EpubScrollDirection.ALLDIRECTIONS,
          allowSharing: true,
          enableTts: true,
        );

        EpubViewer.open(file.path);

        EpubViewer.locatorStream.listen((locator) {
          print('LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator))}');
        });
      }

Here I am not getting that log for LOCATOR

viper22223 commented 2 years ago

final readLocator = EpubLocator.fromJson(jsonDecode(locator)); print(readLocator.href);

how can use it pls send if you want

pranjalpc99 commented 2 years ago

@pranjalpc99 your call is going into the listening part? See here is my code if you get any error into this please let me know

if (await file.exists()) {
        EpubViewer.setConfig(
          themeColor: Color(0xFFA1687C),
          identifier: 'iosBook',
          scrollDirection: EpubScrollDirection.ALLDIRECTIONS,
          allowSharing: true,
          enableTts: true,
        );

        EpubViewer.open(file.path);

        EpubViewer.locatorStream.listen((locator) {
          print('LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator))}');
        });
      }

Here I am not getting that log for LOCATOR

Okay, So what I have done is that I have written the code to listen to the broadcast receiver in the build method inside the try-catch block. Then whenever EpubViewer is called your application will go in the paused state and when you close the EpubViewer the last route will go in resume state and the build method will be called again.

This might be a hack but for me it works.

ghost commented 2 years ago

@pranjalpc99 you might be using openAsset method. I am using only the open method. and I have resolved that issue by done changes to the open method itself...

pranjalpc99 commented 2 years ago

@mustafaMtfa I am also using the open method only. Can you share the changes you did to the open method to resolve the issue?

ghost commented 2 years ago

sure! _channel.invokeMethod('setChannel');

and I have also started the stream before we are open the book like this.

EpubViewer.setConfig(
          themeColor: Color(0xFFA1687C),
          identifier: 'iosBook',
          scrollDirection: EpubScrollDirection.ALLDIRECTIONS,
          allowSharing: true,
          enableTts: true,
        );

        EpubViewer.locatorStream.listen((locator) {
          print('LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator)).toJson()}');
        });

        EpubViewer.open(file.path);
pranjalpc99 commented 2 years ago

@mustafaMtfa what is the purpose of using _channel.invokeMethod('setChannel'); I didn't understand that part. Also, are you able to listen to the stream every time if you start the stream before opening the book. Because I tried and it used to listen only a few times

ghost commented 2 years ago

Actually _channel.invokeMethod('setChannel'); invokes a native method in android or iOS and it starts the listener in native code which returns a stream to locatorStream

pranjalpc99 commented 2 years ago

Ohh Ok. Nice to know that.