需要长时间来显示设备EPUB文件长时间、显示设备、文件、EPUB

2023-09-07 02:16:47 作者:不可一世Struggleを

我们通过我们的应用程序在屏幕上显示的EPUB文件。该文件保存在SD卡和下面的逻辑,我们使用的是从SD卡获取文件数据,并显示在屏幕上。但它需要长时间来加载在屏幕上的内容。我的code的任何问题?请帮助我的朋友。

We are displaying an epub file on the screen through our application. The file is saved in SDCard and the following logic we are using for getting the file data from SDCard and displaying in Screen. But its taking long time to load the content in screen. Any issues with my code? please help me friends.

 File rootDir = Environment.getExternalStorageDirectory();
   EpubReader epubReader = new EpubReader();
   try {
        book = epubReader.readEpub(new FileInputStream("/sdcard/forbook.epub"));
        Toast.makeText(getApplicationContext(), "Book : " + book, Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
        Toast.makeText(getApplicationContext(), "File Not Found" + book, Toast.LENGTH_LONG).show();
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Toast.makeText(getApplicationContext(), "IO Found" + book, Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
   Spine spine = book.getSpine(); 
   List<SpineReference> spineList = spine.getSpineReferences() ;
   int count = spineList.size();
   StringBuilder string = new StringBuilder();
   String linez = null;
    for (int i = 0; count > i; i++) {
       Resource res = spine.getResource(i);

       try {
           InputStream is = res.getInputStream();
           BufferedReader reader = new BufferedReader(new InputStreamReader(is));
           try {
               String line;
            while ((line = reader.readLine()) != null) {
                   linez =   string.append(line + "\n").toString();
                    //linez=line.toString();
               }

           } catch (IOException e) {e.printStackTrace();}

           //do something with stream
       } catch (IOException e) {
           e.printStackTrace();
       }

   }
  final String mimeType = "text/html";
  final String encoding = "UTF-8";
  webView.loadDataWithBaseURL("", linez, mimeType, encoding,null);

}

请帮我的朋友。

推荐答案

这是EPUB是本质上没有什么比拥有一批HTML文件的压缩包内的文件。通常情况下,将会有每本书的章节/部分一个文件(资源)。

An ePub is essentially nothing more than a zip file with a number of HTML files inside. Often, there will be one file (resource) per chapter / section of the book.

你在做什么,现在是循环通过这本书的书脊,加载所有的资源时,你也许可以显示1顶多在屏幕上的时间。

What you're doing right now is looping through the spine of the book, loading all the resources when you can probably display 1 at most on the screen at a time.

我只建议加载要显示资源,这应加快加载时间大大。

I'd suggest only loading the resource you want to show, which should speed up the loading time dramatically.