Update current track bar when player is prepared

This commit is contained in:
Naveen 2023-08-25 19:23:02 +05:30
parent fa6f174497
commit 6c804d2934
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
3 changed files with 12 additions and 10 deletions

View file

@ -79,6 +79,7 @@ class MainActivity : SimpleMusicActivity(), Player.Listener {
withPlayer {
maybePreparePlayer(context = this@MainActivity) { success ->
if (success) {
updateCurrentTrackBar()
broadcastUpdateWidgetState()
}
}

View file

@ -25,6 +25,7 @@ abstract class SimpleMusicActivity : SimpleControllerActivity(), Player.Listener
fun setupCurrentTrackBar(trackBar: CurrentTrackBar) {
trackBarView = trackBar
trackBarView?.initialize { withPlayer { togglePlayback() } }
trackBarView?.setOnClickListener {
hideKeyboard()
handleNotificationPermission { granted ->
@ -39,15 +40,12 @@ abstract class SimpleMusicActivity : SimpleControllerActivity(), Player.Listener
}
}
private fun updateCurrentTrackBar() {
if (trackBarView != null) {
fun updateCurrentTrackBar() {
trackBarView?.apply {
withPlayer {
trackBarView?.initialize {
withPlayer { togglePlayback() }
}
trackBarView?.updateCurrentTrack(currentMediaItem)
trackBarView?.updateTrackState(isReallyPlaying)
updateColors()
updateCurrentTrack(currentMediaItem)
updateTrackState(isReallyPlaying)
}
}
}

View file

@ -24,13 +24,16 @@ import kotlinx.android.synthetic.main.view_current_track_bar.view.current_track_
class CurrentTrackBar(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
fun initialize(togglePlayback: () -> Unit) {
background = ColorDrawable(context.getProperBackgroundColor())
current_track_label.setTextColor(context.getProperTextColor())
current_track_play_pause.setOnClickListener {
togglePlayback()
}
}
fun updateColors() {
background = ColorDrawable(context.getProperBackgroundColor())
current_track_label.setTextColor(context.getProperTextColor())
}
fun updateCurrentTrack(mediaItem: MediaItem?) {
val track = mediaItem?.toTrack()
if (track == null) {