Merge branch 'gedoor:master' into master

pull/1296/head
ag2s20150909 3 years ago committed by GitHub
commit 28bcf5960a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/src/main/java/io/legado/app/help/ExoPlayerHelper.kt
  2. 6
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -10,18 +10,16 @@ import com.google.android.exoplayer2.source.dash.DashMediaSource
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource
import com.google.android.exoplayer2.util.Util.inferContentType
import io.legado.app.help.http.okHttpClient
object ExoPlayerHelper {
fun createMediaSource(
uri: Uri,
overrideExtension: String? = null,
userAgent: String
dataSourceFactory: OkHttpDataSource.Factory,
overrideExtension: String? = null
): MediaSource {
val mediaItem = MediaItem.fromUri(uri)
val dataSourceFactory = OkHttpDataSource.Factory(okHttpClient).setUserAgent(userAgent)
val mediaSourceFactory = when (inferContentType(uri, overrideExtension)) {
C.TYPE_SS -> SsMediaSource.Factory(dataSourceFactory)
C.TYPE_DASH -> DashMediaSource.Factory(dataSourceFactory)

@ -16,6 +16,7 @@ import androidx.media.AudioFocusRequestCompat
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
@ -27,6 +28,7 @@ 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.http.okHttpClient
import io.legado.app.model.AudioPlay
import io.legado.app.model.ReadAloud
import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -133,8 +135,10 @@ class AudioPlayService : BaseService(),
useWebView = true
)
val uri = Uri.parse(analyzeUrl.url)
val dataSourceFactory = OkHttpDataSource.Factory(okHttpClient)
.setDefaultRequestProperties(analyzeUrl.headerMap)
val mediaSource = ExoPlayerHelper
.createMediaSource(uri, userAgent = analyzeUrl.getUserAgent())
.createMediaSource(uri, dataSourceFactory)
exoPlayer.setMediaSource(mediaSource)
exoPlayer.playWhenReady = true
exoPlayer.prepare()

Loading…
Cancel
Save