diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 75ece6ed3..4318f368f 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.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("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, diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index e7cd362b3..4674faea8 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -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("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, diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 866339854..cb25801bd 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -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