pull/1744/head
kunfei 3 years ago
parent d97ede312d
commit ac3d79fcd4
  1. 14
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 12
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  3. 3
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -24,6 +24,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.MediaHelp
import io.legado.app.help.exoplayer.ExoPlayerHelper
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.AudioPlay
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.webBook.WebBook
@ -34,8 +35,9 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Main
import splitties.systemservices.audioManager
/**
* 音频播放服务
*/
class AudioPlayService : BaseService(),
AudioManager.OnAudioFocusChangeListener,
Player.Listener {
@ -458,13 +460,19 @@ class AudioPlayService : BaseService(),
}
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
.setSmallIcon(R.drawable.ic_volume_up)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.icon_read_book))
.setOngoing(true)
.setContentTitle(nTitle)
.setContentText(nSubtitle)
.setContentIntent(
activityPendingIntent<AudioPlayActivity>("activity")
)
kotlin.runCatching {
ImageLoader.loadBitmap(this, AudioPlay.book?.getDisplayCover()).submit().get()
}.getOrElse {
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
}.let {
builder.setLargeIcon(it)
}
if (pause) {
builder.addAction(
R.drawable.ic_play_24dp,

@ -17,6 +17,7 @@ import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.*
import io.legado.app.help.MediaHelp
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.receiver.MediaButtonReceiver
@ -29,6 +30,9 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import splitties.systemservices.audioManager
/**
* 朗读服务
*/
abstract class BaseReadAloudService : BaseService(),
AudioManager.OnAudioFocusChangeListener {
@ -311,13 +315,19 @@ abstract class BaseReadAloudService : BaseService(),
nSubtitle = getString(R.string.read_aloud_s)
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
.setSmallIcon(R.drawable.ic_volume_up)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.icon_read_book))
.setOngoing(true)
.setContentTitle(nTitle)
.setContentText(nSubtitle)
.setContentIntent(
activityPendingIntent<ReadBookActivity>("activity")
)
kotlin.runCatching {
ImageLoader.loadBitmap(this, ReadBook.book?.getDisplayCover()).submit().get()
}.getOrElse {
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
}.let {
builder.setLargeIcon(it)
}
if (pause) {
builder.addAction(
R.drawable.ic_play_24dp,

@ -17,6 +17,9 @@ import io.legado.app.model.ReadBook
import io.legado.app.utils.*
import java.util.*
/**
* 本地朗读
*/
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
private var textToSpeech: TextToSpeech? = null

Loading…
Cancel
Save