Prepare player on resume as well
This commit is contained in:
parent
a2103dcdd2
commit
dd6d9da216
4 changed files with 27 additions and 14 deletions
|
@ -56,6 +56,7 @@ class MainActivity : SimpleMusicActivity() {
|
|||
updateMaterialActivityViews(binding.mainCoordinator, binding.mainHolder, useTransparentNavigation = false, useTopSearchMenu = true)
|
||||
storeStateVariables()
|
||||
setupTabs()
|
||||
setupCurrentTrackBar(binding.currentTrackBar.root)
|
||||
|
||||
handlePermission(getPermissionToRequest()) {
|
||||
if (it) {
|
||||
|
@ -69,14 +70,6 @@ class MainActivity : SimpleMusicActivity() {
|
|||
volumeControlStream = AudioManager.STREAM_MUSIC
|
||||
checkWhatsNewDialog()
|
||||
checkAppOnSDCard()
|
||||
withPlayer {
|
||||
maybePreparePlayer(context = this@MainActivity) { success ->
|
||||
if (success) {
|
||||
updateCurrentTrackBar()
|
||||
broadcastUpdateWidgetState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -188,7 +181,6 @@ class MainActivity : SimpleMusicActivity() {
|
|||
initFragments()
|
||||
binding.sleepTimerStop.setOnClickListener { stopSleepTimer() }
|
||||
|
||||
setupCurrentTrackBar(binding.currentTrackBar.root)
|
||||
refreshAllFragments()
|
||||
}
|
||||
|
||||
|
@ -207,6 +199,9 @@ class MainActivity : SimpleMusicActivity() {
|
|||
if (complete) {
|
||||
binding.loadingProgressBar.hide()
|
||||
withPlayer {
|
||||
if (currentMediaItem == null) {
|
||||
maybePreparePlayer()
|
||||
} else {
|
||||
sendCommand(CustomCommands.RELOAD_CONTENT)
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +209,7 @@ class MainActivity : SimpleMusicActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initFragments() {
|
||||
binding.viewPager.adapter = ViewPagerAdapter(this)
|
||||
|
|
|
@ -30,6 +30,7 @@ abstract class SimpleControllerActivity : SimpleActivity(), Player.Listener {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
controller = SimpleMediaController.getInstance(this)
|
||||
maybePreparePlayer()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -42,6 +43,13 @@ abstract class SimpleControllerActivity : SimpleActivity(), Player.Listener {
|
|||
controller.removeListener(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
maybePreparePlayer()
|
||||
}
|
||||
|
||||
open fun onPlayerPrepared(success: Boolean) {}
|
||||
|
||||
fun withPlayer(callback: MediaController.() -> Unit) = controller.withController(callback)
|
||||
|
||||
fun prepareAndPlay(tracks: List<Track>, startIndex: Int = 0, startPositionMs: Long = 0, startActivity: Boolean = true) {
|
||||
|
@ -60,6 +68,14 @@ abstract class SimpleControllerActivity : SimpleActivity(), Player.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
fun maybePreparePlayer() {
|
||||
withPlayer {
|
||||
maybePreparePlayer(context = this@SimpleControllerActivity, callback = ::onPlayerPrepared)
|
||||
}
|
||||
}
|
||||
|
||||
fun togglePlayback() = withPlayer { togglePlayback() }
|
||||
|
||||
fun addTracksToQueue(tracks: List<Track>, callback: () -> Unit) {
|
||||
withPlayer {
|
||||
val currentMediaItemsIds = currentMediaItems.map { it.mediaId }
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
|||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.openNotificationSettings
|
||||
import com.simplemobiletools.musicplayer.extensions.isReallyPlaying
|
||||
import com.simplemobiletools.musicplayer.extensions.togglePlayback
|
||||
import com.simplemobiletools.musicplayer.views.CurrentTrackBar
|
||||
|
||||
/**
|
||||
|
@ -24,7 +23,7 @@ abstract class SimpleMusicActivity : SimpleControllerActivity(), Player.Listener
|
|||
|
||||
fun setupCurrentTrackBar(trackBar: CurrentTrackBar) {
|
||||
trackBarView = trackBar
|
||||
trackBarView?.initialize { withPlayer { togglePlayback() } }
|
||||
trackBarView?.initialize(togglePlayback = ::togglePlayback)
|
||||
trackBarView?.setOnClickListener {
|
||||
hideKeyboard()
|
||||
handleNotificationPermission { granted ->
|
||||
|
@ -39,7 +38,7 @@ abstract class SimpleMusicActivity : SimpleControllerActivity(), Player.Listener
|
|||
}
|
||||
}
|
||||
|
||||
fun updateCurrentTrackBar() {
|
||||
private fun updateCurrentTrackBar() {
|
||||
trackBarView?.apply {
|
||||
withPlayer {
|
||||
updateColors()
|
||||
|
@ -49,6 +48,8 @@ abstract class SimpleMusicActivity : SimpleControllerActivity(), Player.Listener
|
|||
}
|
||||
}
|
||||
|
||||
override fun onPlayerPrepared(success: Boolean) = updateCurrentTrackBar()
|
||||
|
||||
@CallSuper
|
||||
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
||||
trackBarView?.updateCurrentTrack(mediaItem)
|
||||
|
|
|
@ -155,7 +155,7 @@ class TrackActivity : SimpleControllerActivity(), PlaybackSpeedListener {
|
|||
private fun setupButtons() = binding.apply {
|
||||
activityTrackToggleShuffle.setOnClickListener { withPlayer { toggleShuffle() } }
|
||||
activityTrackPrevious.setOnClickListener { withPlayer { forceSeekToPrevious() } }
|
||||
activityTrackPlayPause.setOnClickListener { withPlayer { togglePlayback() } }
|
||||
activityTrackPlayPause.setOnClickListener { togglePlayback() }
|
||||
activityTrackNext.setOnClickListener { withPlayer { forceSeekToNext() } }
|
||||
activityTrackProgressCurrent.setOnClickListener { seekBack() }
|
||||
activityTrackProgressMax.setOnClickListener { seekForward() }
|
||||
|
|
Loading…
Reference in a new issue