Skip to content

Commit d9a92b0

Browse files
committed
feat: play pause button
1 parent 0a1db14 commit d9a92b0

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

app/src/main/java/com/mixtapeo/lyrisync/MainActivity.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@
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"

0 commit comments

Comments
 (0)