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": {
"chapterList": "$.content.content",
"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
}

@ -1,4 +1,4 @@
package io.legado.app.help
package io.legado.app.help.exoplayer
import android.net.Uri
import com.google.android.exoplayer2.MediaItem
@ -46,7 +46,6 @@ object ExoPlayerHelper {
*/
private val okhttpDataFactory by lazy {
OkHttpDataSource.Factory(okHttpClient)
}
/**
@ -61,7 +60,7 @@ object ExoPlayerHelper {
LeastRecentlyUsedCacheEvictor((100 * 1024 * 1024).toLong()),
//记录缓存的数据库
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.Util.castNonNull;
@ -7,6 +7,7 @@ import static java.lang.Math.min;
import android.net.Uri;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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
* written into the cache.
*/
@SuppressWarnings("unused")
public final class OkhttpCacheDataSource implements DataSource {
/**
* {@link DataSource.Factory} for {@link OkhttpCacheDataSource} instances.
*/
@SuppressWarnings("unused")
public static final class Factory implements DataSource.Factory {
private Cache cache;
@ -587,14 +590,14 @@ public final class OkhttpCacheDataSource implements DataSource {
}
@Override
public void addTransferListener(TransferListener transferListener) {
public void addTransferListener(@NonNull TransferListener transferListener) {
checkNotNull(transferListener);
cacheReadDataSource.addTransferListener(transferListener);
upstreamDataSource.addTransferListener(transferListener);
}
@Override
public long open(DataSpec dataSpec) throws IOException {
public long open(@NonNull DataSpec dataSpec) throws IOException {
try {
String key = cacheKeyFactory.buildCacheKey(dataSpec);
DataSpec requestDataSpec = dataSpec.buildUpon().setKey(key).build();
@ -637,7 +640,7 @@ public final class OkhttpCacheDataSource implements DataSource {
}
@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 currentDataSpec = checkNotNull(this.currentDataSpec);
if (length == 0) {
@ -679,12 +682,15 @@ public final class OkhttpCacheDataSource implements DataSource {
}
}
@Override
@SuppressWarnings("NullableProblems")
@Nullable
@Override
public Uri getUri() {
return actualUri;
}
@NonNull
@Override
public Map<String, List<String>> getResponseHeaders() {
// TODO: Implement.

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

Loading…
Cancel
Save