pull/1295/head
gedoor 3 years ago
parent db178b64cb
commit 263177cc6e
  1. 28
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 23
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 18
      app/src/main/res/menu/audio_play.xml
  4. 1
      app/src/main/res/values-es-rES/strings.xml
  5. 1
      app/src/main/res/values-ja-rJP/strings.xml
  6. 1
      app/src/main/res/values-pt-rBR/strings.xml
  7. 1
      app/src/main/res/values-zh-rHK/strings.xml
  8. 1
      app/src/main/res/values-zh-rTW/strings.xml
  9. 1
      app/src/main/res/values-zh/strings.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -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()
}
}

@ -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<AudioPlayViewModel>()
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<SourceLoginActivity> {
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)

@ -1,11 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/menu_change_source"
android:title="@string/change_origin"
android:icon="@drawable/ic_exchange"
android:title="@string/change_origin"
app:showAsAction="always" />
<item
android:id="@+id/menu_login"
android:title="@string/login"
app:showAsAction="never" />
<item
android:id="@+id/menu_copy_audio_url"
android:title="@string/copy_play_url"
app:showAsAction="never" />
</menu>

@ -871,4 +871,5 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -871,4 +871,5 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -871,5 +871,6 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -868,5 +868,6 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -869,5 +869,6 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -870,5 +870,6 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

@ -871,5 +871,6 @@
<string name="path">路径</string>
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
</resources>

Loading…
Cancel
Save