音频访问传入访问头

pull/1296/head
gedoor 3 years ago
parent 0d895548df
commit 42b850d05d
  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.hls.HlsMediaSource
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource
import com.google.android.exoplayer2.util.Util.inferContentType import com.google.android.exoplayer2.util.Util.inferContentType
import io.legado.app.help.http.okHttpClient
object ExoPlayerHelper { object ExoPlayerHelper {
fun createMediaSource( fun createMediaSource(
uri: Uri, uri: Uri,
overrideExtension: String? = null, dataSourceFactory: OkHttpDataSource.Factory,
userAgent: String overrideExtension: String? = null
): MediaSource { ): MediaSource {
val mediaItem = MediaItem.fromUri(uri) val mediaItem = MediaItem.fromUri(uri)
val dataSourceFactory = OkHttpDataSource.Factory(okHttpClient).setUserAgent(userAgent)
val mediaSourceFactory = when (inferContentType(uri, overrideExtension)) { val mediaSourceFactory = when (inferContentType(uri, overrideExtension)) {
C.TYPE_SS -> SsMediaSource.Factory(dataSourceFactory) C.TYPE_SS -> SsMediaSource.Factory(dataSourceFactory)
C.TYPE_DASH -> DashMediaSource.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.PlaybackException
import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst 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.data.entities.BookChapter
import io.legado.app.help.ExoPlayerHelper import io.legado.app.help.ExoPlayerHelper
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.help.http.okHttpClient
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
@ -133,8 +135,10 @@ class AudioPlayService : BaseService(),
useWebView = true useWebView = true
) )
val uri = Uri.parse(analyzeUrl.url) val uri = Uri.parse(analyzeUrl.url)
val dataSourceFactory = OkHttpDataSource.Factory(okHttpClient)
.setDefaultRequestProperties(analyzeUrl.headerMap)
val mediaSource = ExoPlayerHelper val mediaSource = ExoPlayerHelper
.createMediaSource(uri, userAgent = analyzeUrl.getUserAgent()) .createMediaSource(uri, dataSourceFactory)
exoPlayer.setMediaSource(mediaSource) exoPlayer.setMediaSource(mediaSource)
exoPlayer.playWhenReady = true exoPlayer.playWhenReady = true
exoPlayer.prepare() exoPlayer.prepare()

Loading…
Cancel
Save