File tree Expand file tree Collapse file tree
java/com/mixtapeo/lyrisync Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -370,6 +370,19 @@ class MainActivity : AppCompatActivity() {
370370 }
371371 }
372372
373+ // play pause button
374+ val btnPlayPause = findViewById< android.widget.ImageButton > (R .id.playPause)
375+
376+ btnPlayPause.setOnClickListener {
377+ spotifyAppRemote?.playerApi?.playerState?.setResultCallback { playerState ->
378+ if (playerState.isPaused) {
379+ spotifyAppRemote?.playerApi?.resume()
380+ } else {
381+ spotifyAppRemote?.playerApi?.pause()
382+ }
383+ }
384+ }
385+
373386 // --- 2. SETUP SYNC TOGGLE & ANIMATION ---
374387 val fabReSync = findViewById< com.google.android.material.floatingactionbutton.FloatingActionButton > (R .id.fabReSync)
375388 val syncBtn = findViewById<ToggleButton >(R .id.syncToggleButton)
@@ -669,6 +682,15 @@ class MainActivity : AppCompatActivity() {
669682 private fun connected () {
670683 spotifyAppRemote?.playerApi?.subscribeToPlayerState()?.setEventCallback { playerState ->
671684 val track = playerState.track
685+
686+ // play pause button logic
687+ val btnPlayPause = findViewById< android.widget.ImageButton > (R .id.playPause)
688+ if (playerState.isPaused) {
689+ btnPlayPause.setImageResource(android.R .drawable.ic_media_play)
690+ } else {
691+ btnPlayPause.setImageResource(android.R .drawable.ic_media_pause)
692+ }
693+
672694 if (track != null ) {
673695 if (track.uri != currentTrackUri) {
674696 currentTrackUri = track.uri
Original file line number Diff line number Diff line change 134134 android : textSize =" 16sp"
135135 android : textStyle =" bold" />
136136
137- <ToggleButton
137+ <ImageButton
138138 android : id =" @+id/playPause"
139- android : layout_width =" 40dp"
140- android : layout_height =" match_parent"
141- android : checked =" true"
142- android : textOff =" Manual" />
139+ android : layout_width =" 48dp"
140+ android : layout_height =" 48dp"
141+ android : layout_marginEnd =" 8dp"
142+ android : background =" ?attr/selectableItemBackgroundBorderless"
143+ android : contentDescription =" Play or Pause"
144+ android : scaleType =" centerInside"
145+ app : srcCompat =" @android:drawable/ic_media_pause"
146+ app : tint =" @color/brand_primary" />
143147
144148 <FrameLayout
145149 android : layout_width =" wrap_content"
You can’t perform that action at this time.
0 commit comments