Skip to content

Native Android client for Spotify, built with Jetpack Compose

A mic button beside the search field in both looks opens the phone's voice search for music (the Google app's "Search with your voice"), with a toast where no app answers it, drawn in the look's own colours, in the 12 languages

kota-zo665359232fa5
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/VoiceSearch.kt b/base/app/src/main/java/com/music/spotui/ui/components/VoiceSearch.kt
new file mode 100644
index 00000000..63fe9bbb
--- /dev/null
+++ b/base/app/src/main/java/com/music/spotui/ui/components/VoiceSearch.kt
@@ -0,0 +1,19 @@
+package com.music.spotui.ui.components
+
+import android.content.Context
+import android.content.Intent
+import android.widget.Toast
+import app.myspoti.engine.R
+
+/**
+ * Opens the device's own voice search for music: the exact intent the Google app itself answers
+ * ("Search with your voice"), used as-is rather than building a speech-recognition UI of our own.
+ * Shared by the Classic and Immersive Search screens' mic button. A no-op but a toast if nothing
+ * on the device can handle it (no Google app installed).
+ */
+fun launchVoiceSearch(context: Context) {
+ val intent = Intent("com.google.android.googlequicksearchbox.MUSIC_SEARCH")
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ runCatching { context.startActivity(intent) }
+ .onFailure { Toast.makeText(context, context.getString(R.string.voice_search_unavailable), Toast.LENGTH_SHORT).show() }
+}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveSearchScreen.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveSearchScreen.kt
index 3c0ae3c1..cf43b7b1 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveSearchScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveSearchScreen.kt
@@ -29,6 +29,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Mic
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.material.icons.rounded.Search
@@ -75,6 +76,7 @@ import com.music.spotui.di.Graph
import com.music.spotui.di.SongPlayer
import com.music.spotui.ui.immersive.sheets.ImmersiveSongOptionsSheet
import com.music.spotui.ui.components.SwipeToQueue
+import com.music.spotui.ui.components.launchVoiceSearch
import com.music.spotui.ui.immersive.Immersive
import com.music.spotui.ui.immersive.components.ImmersiveButton
import com.music.spotui.ui.immersive.components.ImmersiveCover
@@ -185,16 +187,24 @@ fun ImmersiveSearchScreen(navController: NavController) {
immersiveLargeTitle(title)
stickyHeader(key = "search:field") {
Column(Modifier.fillMaxWidth().background(Immersive.Page).padding(top = 4.dp, bottom = 6.dp)) {
- ImmersiveSearchField(
- query = text,
- onQueryChange = { vm.search(it) },
- onSubmit = { vm.search(text) },
- focusRequester = fieldFocus,
- placeholder = stringResource(R.string.search_header_field_hint),
- modifier = Modifier
- .padding(horizontal = Immersive.Gutter)
- .onFocusChanged { searchFocused = it.hasFocus },
- )
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier.fillMaxWidth().padding(horizontal = Immersive.Gutter),
+ ) {
+ ImmersiveSearchField(
+ query = text,
+ onQueryChange = { vm.search(it) },
+ onSubmit = { vm.search(text) },
+ focusRequester = fieldFocus,
+ placeholder = stringResource(R.string.search_header_field_hint),
+ modifier = Modifier
+ .weight(1f)
+ .onFocusChanged { searchFocused = it.hasFocus },
+ )
+ Spacer(Modifier.width(8.dp))
+ // Voice search: the Google app's own "Search with your voice" for music.
+ ImmersiveVoiceSearchButton(onClick = { launchVoiceSearch(context) })
+ }
if (text.isNotBlank()) {
ImmersiveChipRow {
val filters = SearchFilter.entries.filter { it != SearchFilter.Podcasts || Features.PODCASTS }
@@ -389,6 +399,26 @@ private fun LazyListScope.recentSearches(
}
}
+/** The mic button beside the search field: opens the device's voice search for music. */
+@Composable
+private fun ImmersiveVoiceSearchButton(onClick: () -> Unit) {
+ Box(
+ contentAlignment = Alignment.Center,
+ modifier = Modifier
+ .size(46.dp)
+ .clip(CircleShape)
+ .background(Immersive.Raised, CircleShape)
+ .clickable(role = Role.Button, onClick = onClick),
+ ) {
+ Icon(
+ Icons.Outlined.Mic,
+ contentDescription = stringResource(R.string.voice_search),
+ tint = Immersive.Text,
+ modifier = Modifier.size(22.dp),
+ )
+ }
+}
+
/** What the engine would complete the half-typed query to: tap to search it. */
@Composable
private fun SuggestionRow(term: String, onClick: () -> Unit) {
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/SearchScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/SearchScreen.kt
index 17e2089d..7006ae6b 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/SearchScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/SearchScreen.kt
@@ -8,6 +8,7 @@ import com.music.spotui.ui.theme.AppMuted
import kotlinx.coroutines.launch
import com.music.spotui.ui.components.SearchClearButton
import com.music.spotui.ui.components.pressable
+import com.music.spotui.ui.components.launchVoiceSearch
import androidx.compose.ui.res.stringResource
import androidx.compose.foundation.ExperimentalFoundationApi
@@ -29,10 +30,12 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
+import androidx.compose.material.icons.outlined.Mic
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
@@ -869,53 +872,77 @@ fun SearchStickyBar(
// The field is always attached to a requester, so the clear button can put the cursor back in it.
val ownFocus = remember { androidx.compose.ui.focus.FocusRequester() }
val fieldFocus = focusRequester ?: ownFocus
- Row(verticalAlignment = Alignment.CenterVertically,
+ val context = LocalContext.current
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
- .padding(10.dp)
- .clip(RoundedCornerShape(10.dp))
- .height(55.dp)
- .background(Color.White)
- .padding(10.dp, 0.dp)
- ){
- Icon(
- painterResource(id = R.drawable.ic_search_big),
- tint = Color.Black,
- contentDescription = "")
-
- TextField(
- enabled = true,
- // The rest of the bar, so the clear button sits at its end and not after a 280 dp field.
+ .padding(10.dp),
+ ) {
+ Row(verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.weight(1f)
- .focusRequester(fieldFocus)
- .onFocusChanged { onFocusChange(it.isFocused) },
- value = text,
- textStyle = TextStyle.Default.copy(fontSize = 16.sp, color = Color.Black, fontWeight = FontWeight(500)),
- colors = TextFieldDefaults.colors(
- unfocusedContainerColor = Color.Transparent,
- disabledContainerColor = Color.Transparent,
- focusedContainerColor = Color.Transparent,
- disabledIndicatorColor = Color.Transparent,
- focusedIndicatorColor = Color.Transparent,
- unfocusedIndicatorColor = Color.Transparent,
- cursorColor = Color.Black
-
- ),
- singleLine = true,
- onValueChange = onTextChange,
- placeholder = {
- Text(
- textAlign = TextAlign.Center,
- fontWeight = FontWeight.Bold,
- text = stringResource(R.string.search_header_field_hint)
+ .clip(RoundedCornerShape(10.dp))
+ .height(55.dp)
+ .background(Color.White)
+ .padding(10.dp, 0.dp)
+ ){
+ Icon(
+ painterResource(id = R.drawable.ic_search_big),
+ tint = Color.Black,
+ contentDescription = "")
+
+ TextField(
+ enabled = true,
+ // The rest of the bar, so the clear button sits at its end and not after a 280 dp field.
+ modifier = Modifier
+ .weight(1f)
+ .focusRequester(fieldFocus)
+ .onFocusChanged { onFocusChange(it.isFocused) },
+ value = text,
+ textStyle = TextStyle.Default.copy(fontSize = 16.sp, color = Color.Black, fontWeight = FontWeight(500)),
+ colors = TextFieldDefaults.colors(
+ unfocusedContainerColor = Color.Transparent,
+ disabledContainerColor = Color.Transparent,
+ focusedContainerColor = Color.Transparent,
+ disabledIndicatorColor = Color.Transparent,
+ focusedIndicatorColor = Color.Transparent,
+ unfocusedIndicatorColor = Color.Transparent,
+ cursorColor = Color.Black
+
+ ),
+ singleLine = true,
+ onValueChange = onTextChange,
+ placeholder = {
+ Text(
+ textAlign = TextAlign.Center,
+ fontWeight = FontWeight.Bold,
+ text = stringResource(R.string.search_header_field_hint)
- )
- },
- trailingIcon = if (text.isEmpty()) null else {
- { SearchClearButton(fieldFocus, Color.Black) { onTextChange("") } }
- },
- )
+ )
+ },
+ trailingIcon = if (text.isEmpty()) null else {
+ { SearchClearButton(fieldFocus, Color.Black) { onTextChange("") } }
+ },
+ )
+ }
+ Spacer(Modifier.width(10.dp))
+ // Voice search: the Google app's own "Search with your voice" for music, one tap away.
+ Box(
+ contentAlignment = Alignment.Center,
+ modifier = Modifier
+ .size(55.dp)
+ .clip(CircleShape)
+ .background(tone(0xFF2A2A2A))
+ .pressable(0.9f) { launchVoiceSearch(context) },
+ ) {
+ Icon(
+ imageVector = Icons.Outlined.Mic,
+ contentDescription = stringResource(R.string.voice_search),
+ tint = AppText,
+ modifier = Modifier.size(24.dp),
+ )
+ }
}
}
diff --git a/base/app/src/main/res/values-de/myspoti_strings.xml b/base/app/src/main/res/values-de/myspoti_strings.xml
index 98352f87..d951c343 100644
--- a/base/app/src/main/res/values-de/myspoti_strings.xml
+++ b/base/app/src/main/res/values-de/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">Um %1$s anzumelden, fragt Spotify einmal nach der Erlaubnis, die seine Desktop-App nutzt. Erlaube sie oder schließe diese Seite. Myspoti liest nur die Adresse, auf der die Seite endet.</string>
<string name="lan_sonos_refused">%1$s braucht eine Spotify-Anmeldung, die Myspoti nicht bekommen hat. Öffne es einmal mit der Spotify-App und versuche es erneut.</string>
<string name="lan_sonos_group">%1$s ist mit anderen Lautsprechern gruppiert: Wähle den Hauptlautsprecher der Gruppe oder hebe die Gruppierung in der Sonos-App auf.</string>
+ <string name="voice_search">Sprachsuche</string>
+ <string name="voice_search_unavailable">Für die Sprachsuche wird die Google-App benötigt</string>
</resources>
diff --git a/base/app/src/main/res/values-el/myspoti_strings.xml b/base/app/src/main/res/values-el/myspoti_strings.xml
index 3862fcc4..9e447954 100644
--- a/base/app/src/main/res/values-el/myspoti_strings.xml
+++ b/base/app/src/main/res/values-el/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">Για να συνδεθεί η συσκευή %1$s, το Spotify ζητά μία φορά την άδεια που χρησιμοποιεί η εφαρμογή του για υπολογιστή. Επιτρέψτε την ή κλείστε αυτή τη σελίδα. Το Myspoti διαβάζει μόνο τη διεύθυνση στην οποία καταλήγει η σελίδα.</string>
<string name="lan_sonos_refused">Η συσκευή %1$s χρειάζεται μια σύνδεση Spotify που το Myspoti δεν μπόρεσε να πάρει. Ανοίξτε την μία φορά με την εφαρμογή Spotify και δοκιμάστε ξανά.</string>
<string name="lan_sonos_group">Η συσκευή %1$s είναι σε ομάδα με άλλα ηχεία: επιλέξτε το κύριο ηχείο της ομάδας ή καταργήστε την ομάδα στην εφαρμογή Sonos.</string>
+ <string name="voice_search">Φωνητική αναζήτηση</string>
+ <string name="voice_search_unavailable">Η φωνητική αναζήτηση χρειάζεται την εφαρμογή Google</string>
</resources>
diff --git a/base/app/src/main/res/values-es/myspoti_strings.xml b/base/app/src/main/res/values-es/myspoti_strings.xml
index 039c4ae7..0b35dc2d 100644
--- a/base/app/src/main/res/values-es/myspoti_strings.xml
+++ b/base/app/src/main/res/values-es/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">Para conectar %1$s, Spotify pide una vez el permiso que usa su app de escritorio. Permítelo o cierra esta página. Myspoti solo lee la dirección en la que termina la página.</string>
<string name="lan_sonos_refused">%1$s necesita un inicio de sesión de Spotify que Myspoti no pudo obtener. Ábrelo una vez con la app de Spotify y vuelve a intentarlo.</string>
<string name="lan_sonos_group">%1$s está agrupado con otros altavoces: elige el altavoz principal del grupo o desagrúpalo en la app de Sonos.</string>
+ <string name="voice_search">Buscar por voz</string>
+ <string name="voice_search_unavailable">La búsqueda por voz necesita la app de Google</string>
</resources>
diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xml
index 5ca8b3eb..fbd8f3fa 100644
--- a/base/app/src/main/res/values-fr/myspoti_strings.xml
+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml
@@ -678,4 +678,6 @@
<string name="lan_sonos_consent">Pour connecter %1$s, Spotify demande une fois l’autorisation qu’utilise son application de bureau. Autorisez-la ou fermez cette page. Myspoti ne lit que l’adresse sur laquelle la page se termine.</string>
<string name="lan_sonos_refused">%1$s demande une connexion Spotify que Myspoti n’a pas pu obtenir. Ouvrez-le une fois avec l’application Spotify, puis réessayez.</string>
<string name="lan_sonos_group">%1$s est groupé avec d’autres enceintes : choisissez l’enceinte principale du groupe, ou dégroupez-le dans l’application Sonos.</string>
+ <string name="voice_search">Rechercher par la voix</string>
+ <string name="voice_search_unavailable">La recherche vocale nécessite l\'application Google</string>
</resources>
diff --git a/base/app/src/main/res/values-it/myspoti_strings.xml b/base/app/src/main/res/values-it/myspoti_strings.xml
index 2f052a87..992f8b21 100644
--- a/base/app/src/main/res/values-it/myspoti_strings.xml
+++ b/base/app/src/main/res/values-it/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">Per collegare %1$s, Spotify chiede una volta il permesso che usa la sua app desktop. Consentilo o chiudi questa pagina. Myspoti legge solo l’indirizzo su cui finisce la pagina.</string>
<string name="lan_sonos_refused">%1$s richiede un accesso a Spotify che Myspoti non è riuscito a ottenere. Aprilo una volta con l’app Spotify, poi riprova.</string>
<string name="lan_sonos_group">%1$s è raggruppato con altri altoparlanti: scegli l’altoparlante principale del gruppo o separalo nell’app Sonos.</string>
+ <string name="voice_search">Cerca con la voce</string>
+ <string name="voice_search_unavailable">La ricerca vocale richiede l\'app Google</string>
</resources>
diff --git a/base/app/src/main/res/values-pl/myspoti_strings.xml b/base/app/src/main/res/values-pl/myspoti_strings.xml
index 2e495ae1..b93f04eb 100644
--- a/base/app/src/main/res/values-pl/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pl/myspoti_strings.xml
@@ -688,4 +688,6 @@
<string name="lan_sonos_consent">Aby zalogować %1$s, Spotify raz prosi o zgodę, z której korzysta jego aplikacja na komputer. Zezwól na nią lub zamknij tę stronę. Myspoti odczytuje tylko adres, na którym kończy się strona.</string>
<string name="lan_sonos_refused">%1$s wymaga logowania Spotify, którego Myspoti nie mógł uzyskać. Otwórz go raz w aplikacji Spotify i spróbuj ponownie.</string>
<string name="lan_sonos_group">%1$s jest zgrupowany z innymi głośnikami: wybierz główny głośnik grupy albo rozgrupuj go w aplikacji Sonos.</string>
+ <string name="voice_search">Szukaj głosowo</string>
+ <string name="voice_search_unavailable">Wyszukiwanie głosowe wymaga aplikacji Google</string>
</resources>
diff --git a/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml b/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml
index 1a4b3f0e..846bfb64 100644
--- a/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml
@@ -651,4 +651,6 @@
<string name="lan_sonos_consent">Para conectar %1$s, o Spotify pede uma vez a permissão que o app para computador dele usa. Permita ou feche esta página. O Myspoti só lê o endereço em que a página termina.</string>
<string name="lan_sonos_refused">%1$s precisa de um login do Spotify que o Myspoti não conseguiu obter. Abra-o uma vez com o app do Spotify e tente de novo.</string>
<string name="lan_sonos_group">%1$s está agrupado com outros alto-falantes: escolha o alto-falante principal do grupo ou desagrupe-o no app da Sonos.</string>
+ <string name="voice_search">Pesquisar por voz</string>
+ <string name="voice_search_unavailable">A pesquisa por voz precisa do app Google</string>
</resources>
diff --git a/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml b/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml
index dc1d6960..dcd5814c 100644
--- a/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml
@@ -620,4 +620,6 @@
<string name="lan_sonos_consent">Para ligar %1$s, o Spotify pede uma vez a autorização que a sua aplicação para computador utiliza. Autorize-a ou feche esta página. O Myspoti só lê o endereço em que a página termina.</string>
<string name="lan_sonos_refused">%1$s precisa de um início de sessão do Spotify que o Myspoti não conseguiu obter. Abra-o uma vez com a aplicação Spotify e tente novamente.</string>
<string name="lan_sonos_group">%1$s está agrupado com outras colunas: escolha a coluna principal do grupo ou desagrupe-o na aplicação Sonos.</string>
+ <string name="voice_search">Pesquisar por voz</string>
+ <string name="voice_search_unavailable">A pesquisa por voz precisa da app Google</string>
</resources>
diff --git a/base/app/src/main/res/values-pt/myspoti_strings.xml b/base/app/src/main/res/values-pt/myspoti_strings.xml
index 0cdd31e6..9c92218c 100644
--- a/base/app/src/main/res/values-pt/myspoti_strings.xml
+++ b/base/app/src/main/res/values-pt/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">Para conectar %1$s, o Spotify pede uma vez a permissão que o app para computador dele usa. Permita ou feche esta página. O Myspoti só lê o endereço em que a página termina.</string>
<string name="lan_sonos_refused">%1$s precisa de um login do Spotify que o Myspoti não conseguiu obter. Abra-o uma vez com o app do Spotify e tente de novo.</string>
<string name="lan_sonos_group">%1$s está agrupado com outros alto-falantes: escolha o alto-falante principal do grupo ou desagrupe-o no app da Sonos.</string>
+ <string name="voice_search">Pesquisar por voz</string>
+ <string name="voice_search_unavailable">A pesquisa por voz precisa da app Google</string>
</resources>
diff --git a/base/app/src/main/res/values-ru/myspoti_strings.xml b/base/app/src/main/res/values-ru/myspoti_strings.xml
index 95cd5043..0af7044e 100644
--- a/base/app/src/main/res/values-ru/myspoti_strings.xml
+++ b/base/app/src/main/res/values-ru/myspoti_strings.xml
@@ -688,4 +688,6 @@
<string name="lan_sonos_consent">Чтобы подключить %1$s, Spotify один раз запрашивает разрешение, которое использует его приложение для компьютера. Разрешите его или закройте эту страницу. Myspoti читает только адрес, на котором заканчивается страница.</string>
<string name="lan_sonos_refused">%1$s требует входа в Spotify, который Myspoti не удалось получить. Откройте его один раз в приложении Spotify и повторите попытку.</string>
<string name="lan_sonos_group">%1$s сгруппирован с другими колонками: выберите главную колонку группы или разгруппируйте его в приложении Sonos.</string>
+ <string name="voice_search">Голосовой поиск</string>
+ <string name="voice_search_unavailable">Для голосового поиска нужно приложение Google</string>
</resources>
diff --git a/base/app/src/main/res/values-zh/myspoti_strings.xml b/base/app/src/main/res/values-zh/myspoti_strings.xml
index be302266..3717d189 100644
--- a/base/app/src/main/res/values-zh/myspoti_strings.xml
+++ b/base/app/src/main/res/values-zh/myspoti_strings.xml
@@ -673,4 +673,6 @@
<string name="lan_sonos_consent">要登录 %1$s,Spotify 会询问一次其桌面应用所用的授权。请允许,或关闭此页面。Myspoti 只读取页面最终跳转到的地址。</string>
<string name="lan_sonos_refused">%1$s 需要 Myspoti 无法获取的 Spotify 登录。请先用 Spotify 应用打开它一次,然后重试。</string>
<string name="lan_sonos_group">%1$s 与其他音箱编组:请选择该组的主音箱,或在 Sonos 应用中取消编组。</string>
+ <string name="voice_search">语音搜索</string>
+ <string name="voice_search_unavailable">语音搜索需要安装 Google 应用</string>
</resources>
diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xml
index bb027ca2..3ba479a4 100644
--- a/base/app/src/main/res/values/myspoti_strings.xml
+++ b/base/app/src/main/res/values/myspoti_strings.xml
@@ -679,4 +679,6 @@
<string name="lan_sonos_consent">To log in %1$s, Spotify asks once for the permission its desktop app uses. Allow it, or close this page. Myspoti only reads the address the page ends on.</string>
<string name="lan_sonos_refused">%1$s needs a Spotify login Myspoti could not get. Open it once with the Spotify app, then try again.</string>
<string name="lan_sonos_group">%1$s is grouped with other speakers: pick the group’s main speaker, or ungroup it in the Sonos app.</string>
+ <string name="voice_search">Search by voice</string>
+ <string name="voice_search_unavailable">Voice search needs the Google app installed</string>
</resources>