Update current track bar when player is prepared
This commit is contained in:
parent
fa6f174497
commit
6c804d2934
3 changed files with 12 additions and 10 deletions
|
@ -79,6 +79,7 @@ class MainActivity : SimpleMusicActivity(), Player.Listener {
|
|||
withPlayer {
|
||||
maybePreparePlayer(context = this@MainActivity) { success ->
|
||||
if (success) {
|
||||
updateCurrentTrackBar()
|
||||
broadcastUpdateWidgetState()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue