优化
This commit is contained in:
@@ -56,15 +56,15 @@ object CookieManager {
|
|||||||
val cookie = CookieStore.getCookie(domain)
|
val cookie = CookieStore.getCookie(domain)
|
||||||
val requestCookie = request.header("Cookie")
|
val requestCookie = request.header("Cookie")
|
||||||
|
|
||||||
mergeCookies(cookie, requestCookie)?.let { cookie ->
|
mergeCookies(cookie, requestCookie)?.let { newCookie ->
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
return request.newBuilder()
|
return request.newBuilder()
|
||||||
.header("Cookie", cookie)
|
.header("Cookie", newCookie)
|
||||||
.build()
|
.build()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
CookieStore.removeCookie(url)
|
CookieStore.removeCookie(url)
|
||||||
AppLog.put(
|
AppLog.put(
|
||||||
"设置cookie出错,已清除cookie $domain cookie:$cookie\n${it.localizedMessage}",
|
"设置cookie出错,已清除cookie $domain cookie:$newCookie\n${it.localizedMessage}",
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.content.IntentFilter
|
|||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.support.v4.media.MediaMetadataCompat
|
import android.support.v4.media.MediaMetadataCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
@@ -61,6 +62,14 @@ class AudioPlayService : BaseService(),
|
|||||||
|
|
||||||
var url: String = ""
|
var url: String = ""
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
private const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_PLAY
|
||||||
|
or PlaybackStateCompat.ACTION_PAUSE
|
||||||
|
or PlaybackStateCompat.ACTION_PLAY_PAUSE
|
||||||
|
or PlaybackStateCompat.ACTION_SEEK_TO)
|
||||||
|
|
||||||
|
private const val APP_ACTION_STOP = "Stop"
|
||||||
|
private const val APP_ACTION_TIMER = "Timer"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val useWakeLock = AppConfig.audioPlayUseWakeLock
|
private val useWakeLock = AppConfig.audioPlayUseWakeLock
|
||||||
@@ -74,7 +83,7 @@ class AudioPlayService : BaseService(),
|
|||||||
MediaHelp.buildAudioFocusRequestCompat(this)
|
MediaHelp.buildAudioFocusRequestCompat(this)
|
||||||
}
|
}
|
||||||
private val exoPlayer: ExoPlayer by lazy {
|
private val exoPlayer: ExoPlayer by lazy {
|
||||||
ExoPlayerHelper.createHttpExoPlayer(this)
|
ExoPlayerHelper.createHttpExoPlayer(this)
|
||||||
}
|
}
|
||||||
private var mediaSessionCompat: MediaSessionCompat? = null
|
private var mediaSessionCompat: MediaSessionCompat? = null
|
||||||
private var broadcastReceiver: BroadcastReceiver? = null
|
private var broadcastReceiver: BroadcastReceiver? = null
|
||||||
@@ -152,7 +161,12 @@ class AudioPlayService : BaseService(),
|
|||||||
chapter = AudioPlay.durChapter,
|
chapter = AudioPlay.durChapter,
|
||||||
headerMapF = AudioPlay.headers(true),
|
headerMapF = AudioPlay.headers(true),
|
||||||
)
|
)
|
||||||
exoPlayer.setMediaItem(ExoPlayerHelper.createMediaItem(analyzeUrl.url,analyzeUrl.headerMap))
|
exoPlayer.setMediaItem(
|
||||||
|
ExoPlayerHelper.createMediaItem(
|
||||||
|
analyzeUrl.url,
|
||||||
|
analyzeUrl.headerMap
|
||||||
|
)
|
||||||
|
)
|
||||||
exoPlayer.playWhenReady = true
|
exoPlayer.playWhenReady = true
|
||||||
exoPlayer.prepare()
|
exoPlayer.prepare()
|
||||||
}.onError {
|
}.onError {
|
||||||
@@ -419,9 +433,19 @@ class AudioPlayService : BaseService(),
|
|||||||
private fun upMediaSessionPlaybackState(state: Int) {
|
private fun upMediaSessionPlaybackState(state: Int) {
|
||||||
mediaSessionCompat?.setPlaybackState(
|
mediaSessionCompat?.setPlaybackState(
|
||||||
PlaybackStateCompat.Builder()
|
PlaybackStateCompat.Builder()
|
||||||
.setActions(PlaybackStateCompat.ACTION_SEEK_TO)
|
.setActions(MEDIA_SESSION_ACTIONS)
|
||||||
.setState(state, exoPlayer.currentPosition, 1f)
|
.setState(state, exoPlayer.currentPosition, 1f)
|
||||||
.setBufferedPosition(exoPlayer.bufferedPosition)
|
.setBufferedPosition(exoPlayer.bufferedPosition)
|
||||||
|
.addCustomAction(
|
||||||
|
APP_ACTION_STOP,
|
||||||
|
getString(R.string.set_timer),
|
||||||
|
R.drawable.ic_stop_black_24dp
|
||||||
|
)
|
||||||
|
.addCustomAction(
|
||||||
|
APP_ACTION_TIMER,
|
||||||
|
getString(R.string.set_timer),
|
||||||
|
R.drawable.ic_time_add_24dp
|
||||||
|
)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -441,6 +465,19 @@ class AudioPlayService : BaseService(),
|
|||||||
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
|
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
|
||||||
return MediaButtonReceiver.handleIntent(this@AudioPlayService, mediaButtonEvent)
|
return MediaButtonReceiver.handleIntent(this@AudioPlayService, mediaButtonEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPlay() = resume()
|
||||||
|
|
||||||
|
override fun onPause() = pause()
|
||||||
|
|
||||||
|
override fun onCustomAction(action: String?, extras: Bundle?) {
|
||||||
|
action ?: return
|
||||||
|
|
||||||
|
when (action) {
|
||||||
|
APP_ACTION_STOP -> stopSelf()
|
||||||
|
APP_ACTION_TIMER -> addTimer()
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
mediaSessionCompat?.setMediaButtonReceiver(
|
mediaSessionCompat?.setMediaButtonReceiver(
|
||||||
broadcastPendingIntent<MediaButtonReceiver>(Intent.ACTION_MEDIA_BUTTON)
|
broadcastPendingIntent<MediaButtonReceiver>(Intent.ACTION_MEDIA_BUTTON)
|
||||||
|
|||||||
Reference in New Issue
Block a user