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 0a93d6c02..9ae6df41a 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -49,6 +49,7 @@ class AudioPlayService : BaseService(), var isRun = false var pause = false var timeMinute: Int = 0 + var url: String = "" } private lateinit var audioManager: AudioManager @@ -58,7 +59,6 @@ class AudioPlayService : BaseService(), private var subtitle: String = "" private var mediaSessionCompat: MediaSessionCompat? = null private var broadcastReceiver: BroadcastReceiver? = null - private var url: String = "" private var position = 0 private var dsJob: Job? = null private var upPlayProgressJob: Job? = null @@ -144,21 +144,17 @@ class AudioPlayService : BaseService(), } private fun pause(pause: Boolean) { - if (url.contains(".m3u8", false)) { - stopSelf() - } else { - try { - AudioPlayService.pause = pause - upPlayProgressJob?.cancel() - position = exoPlayer.currentPosition.toInt() - if (exoPlayer.isPlaying) exoPlayer.pause() - upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) - AudioPlay.status = Status.PAUSE - postEvent(EventBus.AUDIO_STATE, Status.PAUSE) - upNotification() - } catch (e: Exception) { - e.printStackTrace() - } + try { + AudioPlayService.pause = pause + upPlayProgressJob?.cancel() + position = exoPlayer.currentPosition.toInt() + if (exoPlayer.isPlaying) exoPlayer.pause() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) + AudioPlay.status = Status.PAUSE + postEvent(EventBus.AUDIO_STATE, Status.PAUSE) + upNotification() + } catch (e: Exception) { + e.printStackTrace() } } diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 03924dc28..acba1ae55 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -22,9 +22,11 @@ import io.legado.app.databinding.ActivityAudioPlayBinding import io.legado.app.help.BlurTransformation import io.legado.app.help.glide.ImageLoader import io.legado.app.lib.dialogs.alert +import io.legado.app.service.AudioPlayService import io.legado.app.service.help.AudioPlay import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.toc.TocActivityResult +import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* @@ -41,7 +43,7 @@ class AudioPlayActivity : override val binding by viewBinding(ActivityAudioPlayBinding::inflate) override val viewModel by viewModels() - + private var menu: Menu? = null private var adjustProgress = false private val progressTimeFormat by lazy { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { @@ -75,11 +77,23 @@ class AudioPlayActivity : return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + this.menu = menu + upMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_change_source -> AudioPlay.book?.let { ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) } + R.id.menu_login -> AudioPlay.bookSource?.let { + startActivity { + putExtra("sourceUrl", it.bookSourceUrl) + } + } + R.id.menu_copy_audio_url -> sendToClip(AudioPlayService.url) } return super.onCompatOptionsItemSelected(item) } @@ -131,6 +145,13 @@ class AudioPlayActivity : } } + private fun upMenu() { + menu?.let { menu -> + menu.findItem(R.id.menu_login)?.isVisible = + !AudioPlay.bookSource?.loginUrl.isNullOrBlank() + } + } + private fun upCover(path: String?) { ImageLoader.load(this, path) .placeholder(CoverImageView.defaultDrawable) diff --git a/app/src/main/res/menu/audio_play.xml b/app/src/main/res/menu/audio_play.xml index 871c9e298..a313756ce 100644 --- a/app/src/main/res/menu/audio_play.xml +++ b/app/src/main/res/menu/audio_play.xml @@ -1,11 +1,23 @@ - + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 7ba6bf7ee..64ceb8a66 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -871,4 +871,5 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index de7f2adf4..8426607e0 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -871,4 +871,5 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 4d24442de..c3cf77417 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -871,5 +871,6 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index e35fcf9c5..03165419b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -868,5 +868,6 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index f5168a640..91d8d023b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -869,5 +869,6 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3e58e0270..634c13677 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -870,5 +870,6 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad6234981..a2dac3821 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -871,5 +871,6 @@ 路径 直链上传规则 用于导出书源书单时生成直链url + 拷贝播放Url