From 0d895548df1b67f3bbba25bf4506eb5f7c302d21 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 5 Sep 2021 12:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/AudioPlayService.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 126cbef54..a2a331ead 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -49,9 +49,15 @@ class AudioPlayService : BaseService(), var url: String = "" } - private lateinit var audioManager: AudioManager - private lateinit var mFocusRequest: AudioFocusRequestCompat - private lateinit var exoPlayer: SimpleExoPlayer + private val audioManager: AudioManager by lazy { + getSystemService(Context.AUDIO_SERVICE) as AudioManager + } + private val mFocusRequest: AudioFocusRequestCompat by lazy { + MediaHelp.getFocusRequest(this) + } + private val exoPlayer: SimpleExoPlayer by lazy { + SimpleExoPlayer.Builder(this).build() + } private var title: String = "" private var subtitle: String = "" private var mediaSessionCompat: MediaSessionCompat? = null @@ -65,9 +71,6 @@ class AudioPlayService : BaseService(), super.onCreate() isRun = true upNotification() - audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager - mFocusRequest = MediaHelp.getFocusRequest(this) - exoPlayer = SimpleExoPlayer.Builder(this).build() exoPlayer.addListener(this) initMediaSession() initBroadcastReceiver()