pull/1298/head
gedoor 3 years ago
parent b94312b3e1
commit 4691d250dc
  1. 2
      app/src/main/assets/defaultData/bookSources.json
  2. 5
      app/src/main/java/io/legado/app/help/exoplayer/ExoPlayerHelper.kt
  3. 16
      app/src/main/java/io/legado/app/help/exoplayer/OkhttpCacheDataSource.java
  4. 2
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -40,7 +40,7 @@
"ruleToc": { "ruleToc": {
"chapterList": "$.content.content", "chapterList": "$.content.content",
"chapterName": "$.chapterTitle", "chapterName": "$.chapterTitle",
"chapterUrl": "@js:\"https://www.shuidi.online:9021/fileMgt/getAudioByChapterId?bookId=\"\n + java.getString(\"$.bookId\") + \"&chapterId=\" + java.getString(\"$.id\")\n + \"&pageNum=1&pageSize=50&{{var header = JSON.parse(source.getLoginHeader());'Authorization=' + header.Authorization}}\"" "chapterUrl": "@js:\"https://www.shuidi.online:9021/fileMgt/getAudioByChapterId?bookId=\"\n + java.getString(\"$.bookId\") + \"&chapterId=\" + java.getString(\"$.id\")\n + \"&pageNum=1&pageSize=50\""
}, },
"weight": 0 "weight": 0
} }

@ -1,4 +1,4 @@
package io.legado.app.help package io.legado.app.help.exoplayer
import android.net.Uri import android.net.Uri
import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.MediaItem
@ -46,7 +46,6 @@ object ExoPlayerHelper {
*/ */
private val okhttpDataFactory by lazy { private val okhttpDataFactory by lazy {
OkHttpDataSource.Factory(okHttpClient) OkHttpDataSource.Factory(okHttpClient)
} }
/** /**
@ -61,7 +60,7 @@ object ExoPlayerHelper {
LeastRecentlyUsedCacheEvictor((100 * 1024 * 1024).toLong()), LeastRecentlyUsedCacheEvictor((100 * 1024 * 1024).toLong()),
//记录缓存的数据库 //记录缓存的数据库
databaseProvider databaseProvider
); )
} }

@ -1,4 +1,4 @@
package io.legado.app.help; package io.legado.app.help.exoplayer;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Util.castNonNull; import static com.google.android.exoplayer2.util.Util.castNonNull;
@ -7,6 +7,7 @@ import static java.lang.Math.min;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
@ -45,11 +46,13 @@ import java.util.Map;
* when possible. When data is not cached it is requested from an upstream {@link DataSource} and * when possible. When data is not cached it is requested from an upstream {@link DataSource} and
* written into the cache. * written into the cache.
*/ */
@SuppressWarnings("unused")
public final class OkhttpCacheDataSource implements DataSource { public final class OkhttpCacheDataSource implements DataSource {
/** /**
* {@link DataSource.Factory} for {@link OkhttpCacheDataSource} instances. * {@link DataSource.Factory} for {@link OkhttpCacheDataSource} instances.
*/ */
@SuppressWarnings("unused")
public static final class Factory implements DataSource.Factory { public static final class Factory implements DataSource.Factory {
private Cache cache; private Cache cache;
@ -587,14 +590,14 @@ public final class OkhttpCacheDataSource implements DataSource {
} }
@Override @Override
public void addTransferListener(TransferListener transferListener) { public void addTransferListener(@NonNull TransferListener transferListener) {
checkNotNull(transferListener); checkNotNull(transferListener);
cacheReadDataSource.addTransferListener(transferListener); cacheReadDataSource.addTransferListener(transferListener);
upstreamDataSource.addTransferListener(transferListener); upstreamDataSource.addTransferListener(transferListener);
} }
@Override @Override
public long open(DataSpec dataSpec) throws IOException { public long open(@NonNull DataSpec dataSpec) throws IOException {
try { try {
String key = cacheKeyFactory.buildCacheKey(dataSpec); String key = cacheKeyFactory.buildCacheKey(dataSpec);
DataSpec requestDataSpec = dataSpec.buildUpon().setKey(key).build(); DataSpec requestDataSpec = dataSpec.buildUpon().setKey(key).build();
@ -637,7 +640,7 @@ public final class OkhttpCacheDataSource implements DataSource {
} }
@Override @Override
public int read(byte[] buffer, int offset, int length) throws IOException { public int read(@NonNull byte[] buffer, int offset, int length) throws IOException {
DataSpec requestDataSpec = checkNotNull(this.requestDataSpec); DataSpec requestDataSpec = checkNotNull(this.requestDataSpec);
DataSpec currentDataSpec = checkNotNull(this.currentDataSpec); DataSpec currentDataSpec = checkNotNull(this.currentDataSpec);
if (length == 0) { if (length == 0) {
@ -679,12 +682,15 @@ public final class OkhttpCacheDataSource implements DataSource {
} }
} }
@Override
@SuppressWarnings("NullableProblems")
@Nullable @Nullable
@Override
public Uri getUri() { public Uri getUri() {
return actualUri; return actualUri;
} }
@NonNull
@Override @Override
public Map<String, List<String>> getResponseHeaders() { public Map<String, List<String>> getResponseHeaders() {
// TODO: Implement. // TODO: Implement.

@ -25,8 +25,8 @@ import io.legado.app.constant.Status
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.ExoPlayerHelper
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.help.exoplayer.ExoPlayerHelper
import io.legado.app.model.AudioPlay import io.legado.app.model.AudioPlay
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl

Loading…
Cancel
Save