Open-source music player for YouTube Music's catalog, with genres, full albums and playlists. Windows, macOS, Linux, Android, iPhone and Docker. No account needed.
TypeScript
feat(android): one APK for phones and Android TV (1.4.2)
Ernanic9c294161b57
diff --git a/README.md b/README.mdindex 93b33f6..f622ecb 100644--- a/README.md+++ b/README.md@@ -7,7 +7,7 @@**Your music, uninterrupted.**A personal music player for YouTube's catalog: any song or music video, as **audio** or **video**, with no ads, no account and no subscription.-Runs as a **Windows**, **macOS** and **Linux** app, as an **Android** app that needs no computer, in any **browser** (installable PWA) and in **Docker**.+Runs as a **Windows**, **macOS** and **Linux** app, as an **Android** and **Android TV** app that needs no computer, in any **browser** (installable PWA) and in **Docker**.@@ -90,6 +90,7 @@ Musike started from the idea behind the old Discord music bots: a server that fe- **Standalone:** no computer, no server. The phone searches YouTube Music and plays the audio straight from YouTube- Same app as on the computer: search, genres, artists, albums, Search a list, playlists, favorites, themes and colors- Keeps playing with the screen off, with controls in the notification, on the lock screen and on headphones; pauses for calls and when headphones are unplugged+- **Android TV:** the same app appears in the TV launcher and switches to a bigger interface you navigate with the remote- Audio only for now (no video mode)**Self-hosting**@@ -216,6 +217,7 @@ On the phone, download `Musike-Setup-<version>-Android.apk` from the [latest rel- Your playlists and favorites live on the phone. To move them to or from a computer, use [backup to a file](#moving-your-library-backup) (on Android, Export opens the share sheet: save to Files or Drive, or send it to yourself).- **To update,** install the new APK over the old one. Your library stays.- Audio only for now: the video mode is available on the desktop app and in the browser.+- **Android TV:** install the same APK on the TV (for example with a file manager app, or `adb install`). Musike shows up in the TV launcher and switches to a remote-friendly interface by itself.To build the APK yourself you need JDK 21 and the Android SDK (Android Studio installs both): `pnpm install && pnpm --filter @musike/mobile apk` (creates `release/Musike-Setup-<version>-Android.apk`; unsigned unless `mobile/android/keystore.properties` points to your signing key).@@ -397,6 +399,7 @@ musike/│ ├─ views/ Home, Search, Library, playlists, genres, artists, albums│ ├─ i18n/ English (the source) and Portuguese│ ├─ native/ Android: server code running in the app, streams, media controls+│ ├─ tv/ Android TV: remote (D-pad) navigation and the 10-foot interface│ └─ stores/ state (zustand), appearance preferences├─ desktop/ Electron: window, built-in server, Windows installer, macOS and Linux packages├─ mobile/ Android app (Capacitor): playback service, signing, streaming.jsondiff --git a/desktop/package.json b/desktop/package.jsonindex 7a224d2..8cbdcd8 100644--- a/desktop/package.json+++ b/desktop/package.json@@ -1,7 +1,7 @@{"name": "musike-desktop","productName": "Musike",- "version": "1.4.1",+ "version": "1.4.2","description": "Your music, uninterrupted.","author": "Musike","homepage": "https://github.com/Ernani1234/musike",diff --git a/docs/tv-screenshot.png b/docs/tv-screenshot.pngdeleted file mode 100644index 403f2f3..0000000Binary files a/docs/tv-screenshot.png and /dev/null differdiff --git a/mobile/android/app/src/main/AndroidManifest.xml b/mobile/android/app/src/main/AndroidManifest.xmlindex 01bbd51..c50f1bd 100644--- a/mobile/android/app/src/main/AndroidManifest.xml+++ b/mobile/android/app/src/main/AndroidManifest.xml@@ -15,7 +15,7 @@<applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"- android:banner="@mipmap/ic_launcher"+ android:banner="@drawable/banner"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"diff --git a/mobile/android/app/src/main/java/app/musike/android/MainActivity.java b/mobile/android/app/src/main/java/app/musike/android/MainActivity.javaindex b76d646..b877e23 100644--- a/mobile/android/app/src/main/java/app/musike/android/MainActivity.java+++ b/mobile/android/app/src/main/java/app/musike/android/MainActivity.java@@ -11,6 +11,7 @@ public class MainActivity extends BridgeActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {registerPlugin(MusikePlaybackPlugin.class);+ registerPlugin(MusikeDevicePlugin.class);super.onCreate(savedInstanceState);// Draw behind the status and navigation bars on every Android version; the page pads itself// (env(safe-area-inset-*)) and the SystemBars plugin keeps the icons readable for the theme.diff --git a/mobile/android/app/src/main/java/app/musike/android/MusikeDevicePlugin.java b/mobile/android/app/src/main/java/app/musike/android/MusikeDevicePlugin.javanew file mode 100644index 0000000..0c66b22--- /dev/null+++ b/mobile/android/app/src/main/java/app/musike/android/MusikeDevicePlugin.java@@ -0,0 +1,28 @@+package app.musike.android;++import android.app.UiModeManager;+import android.content.Context;+import android.content.pm.PackageManager;+import android.content.res.Configuration;+import com.getcapacitor.JSObject;+import com.getcapacitor.Plugin;+import com.getcapacitor.PluginCall;+import com.getcapacitor.PluginMethod;+import com.getcapacitor.annotation.CapacitorPlugin;++/** What kind of device the app runs on (web/src/native/android.ts): the same APK serves phones and Android TV. */+@CapacitorPlugin(name = "MusikeDevice")+public class MusikeDevicePlugin extends Plugin {++ @PluginMethod+ public void info(PluginCall call) {+ Context context = getContext();+ UiModeManager uiMode = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);+ boolean tv =+ (uiMode != null && uiMode.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) ||+ context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);+ JSObject result = new JSObject();+ result.put("tv", tv);+ call.resolve(result);+ }+}diff --git a/mobile/android/app/src/main/res/drawable-xhdpi/banner.png b/mobile/android/app/src/main/res/drawable-xhdpi/banner.pngnew file mode 100644index 0000000..4ddd88eBinary files /dev/null and b/mobile/android/app/src/main/res/drawable-xhdpi/banner.png differdiff --git a/mobile/package.json b/mobile/package.jsonindex 77411d8..6fd4e4e 100644--- a/mobile/package.json+++ b/mobile/package.json@@ -1,7 +1,7 @@{"name": "@musike/mobile","private": true,- "version": "1.4.1",+ "version": "1.4.2","description": "Musike for Android: the web app with the server's work done on the phone (Capacitor).","type": "module","scripts": {diff --git a/package.json b/package.jsonindex 72ba915..d59ec92 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "musike","private": true,- "version": "1.4.1",+ "version": "1.4.2","type": "module","scripts": {"dev": "pnpm --parallel --filter ./server --filter ./web dev",diff --git a/server/package.json b/server/package.jsonindex ccdc567..ac0a595 100644--- a/server/package.json+++ b/server/package.json@@ -1,7 +1,7 @@{"name": "@musike/server","private": true,- "version": "1.4.1",+ "version": "1.4.2","type": "module","scripts": {"dev": "tsx watch --clear-screen=false src/index.ts",diff --git a/tools/build-apk-tv.sh b/tools/build-apk-tv.shdeleted file mode 100755index 346583c..0000000--- a/tools/build-apk-tv.sh+++ /dev/null@@ -1,24 +0,0 @@-#!/usr/bin/env bash-# Android TV build: web bundle in TV mode -> Capacitor sync -> debug APK -> install.-set -euo pipefail-cd "$(dirname "$0")/.."-export JAVA_HOME="${JAVA_HOME:-/opt/homebrew/opt/openjdk@21}" # Capacitor 8 needs Java 21-export ANDROID_HOME="${ANDROID_HOME:-$HOME/Library/Android/sdk}"-export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$PATH"-TV_HOST="${TV_HOST:-192.168.1.157:5555}"--echo "== web bundle (TV mode) =="-VITE_TV=1 pnpm --filter @musike/web build:native--echo "== capacitor sync =="-(cd mobile && npx cap sync android)--echo "== gradle =="-(cd mobile/android && ./gradlew assembleDebug --console=plain | tail -5)--APK=mobile/android/app/build/outputs/apk/debug/app-debug.apk-echo "== install to $TV_HOST =="-adb connect "$TV_HOST" >/dev/null 2>&1 || true-adb -s "$TV_HOST" install -r "$APK"-adb -s "$TV_HOST" shell 'am force-stop app.musike.android; monkey -p app.musike.android -c android.intent.category.LEANBACK_LAUNCHER 1' >/dev/null 2>&1 || true-echo "done: $APK"diff --git a/web/package.json b/web/package.jsonindex 88a50cb..f260027 100644--- a/web/package.json+++ b/web/package.json@@ -1,7 +1,7 @@{"name": "@musike/web","private": true,- "version": "1.4.1",+ "version": "1.4.2","type": "module","scripts": {"dev": "vite --host",diff --git a/web/src/native/android.ts b/web/src/native/android.tsindex 15eb944..19d6a9b 100644--- a/web/src/native/android.ts+++ b/web/src/native/android.ts@@ -1,8 +1,23 @@import { App } from "@capacitor/app";-import { Capacitor, SystemBars, SystemBarsStyle } from "@capacitor/core";+import { Capacitor, registerPlugin, SystemBars, SystemBarsStyle } from "@capacitor/core";+import { installTvMode } from "../tv/tvMode";-// How the app fits into Android itself: the Back button and the system bars.+/** MusikeDevicePlugin.java: what kind of device this is. */+const Device = registerPlugin<{ info(): Promise<{ tv: boolean }> }>("MusikeDevice", {+ web: () => ({ info: async () => ({ tv: false }) }),+});++// How the app fits into Android itself: Android TV, the Back button and the system bars.if (Capacitor.isNativePlatform()) {+ // One APK for phones and TVs: on a TV, switch to the remote-friendly 10-foot UI (web/src/tv).+ void Device.info()+ .then(({ tv }) => {+ if (!tv) return;+ document.documentElement.dataset.tv = "1";+ installTvMode();+ })+ .catch(() => {});+// Back closes what's on top (a dialog, a menu), then goes back through pages, then sends the app to the// background, where the music keeps playing.void App.addListener("backButton", () => {diff --git a/web/src/styles.css b/web/src/styles.cssindex 25f7cec..caf8dd6 100644--- a/web/src/styles.css+++ b/web/src/styles.css@@ -1,10 +1,10 @@@import "tailwindcss";@custom-variant light (&:where([data-theme="light"], [data-theme="light"] *));-/* The wide (labelled) rail, from 1280px up unless the user chose a compact sidebar in Settings. */+/* The wide (labelled) rail, from 1280px up unless the user chose a compact sidebar in Settings (always compact on TV). */@custom-variant wide {@media (width >= 80rem) {- &:where(html:not([data-rail="compact"]) *) {+ &:where(html:not([data-rail="compact"]):not([data-tv="1"]) *) {@slot;}}diff --git a/web/src/tv/tvMode.ts b/web/src/tv/tvMode.tsindex 657dd6d..c8f7b85 100644--- a/web/src/tv/tvMode.ts+++ b/web/src/tv/tvMode.ts@@ -1,8 +1,8 @@/*** Android TV mode: 10-foot UI plus D-pad spatial navigation.*- * Enabled by VITE_TV=1 at build time (tools/build-apk-tv.sh) or by opening the app with ?tv=1,- * so the normal desktop/mobile builds are untouched.+ * Turned on automatically when the Android app runs on a TV (web/src/native/android.ts), by VITE_TV=1 at build+ * time, or by opening the app with ?tv=1 (handy for trying it in a browser). Everywhere else it stays off.** Rules: geometry in document space (rails stay navigable when an item is scrolled out), candidates* overlapping the current element on the other axis win, the nearest scrollable ancestor is scrolled@@ -38,11 +38,19 @@ function shown(el: HTMLElement): boolean {return r.width >= 4 && r.height >= 4;}-/** The topmost open dialog/sheet, if any. While one is open the D-pad stays inside it. */+/** On screen, even while still transparent: dialogs open with a fade-in, and must count from the first frame. */+function present(el: HTMLElement): boolean {+ const style = getComputedStyle(el);+ if (style.display === "none" || style.visibility === "hidden") return false;+ const r = el.getBoundingClientRect();+ return r.width >= 4 && r.height >= 4;+}++/** The topmost open dialog, sheet or menu, if any. While one is open the D-pad stays inside it. */function activeDialog(): HTMLElement | null {const nodes = Array.from(- document.querySelectorAll<HTMLElement>('[role="dialog"], [aria-modal="true"], dialog[open]'),- ).filter(shown);+ document.querySelectorAll<HTMLElement>('[role="dialog"], [aria-modal="true"], dialog[open], [role="menu"]'),+ ).filter(present);return nodes.length ? nodes[nodes.length - 1] : null;}@@ -204,7 +212,9 @@ export function installTvMode() {}if (key === "Escape" || key === "BrowserBack" || key === "GoBack") {- if (activeDialog()) return; // the app's own Escape handler closes it+ // A dialog or a menu is open: the app's own Escape handler closes it (and nothing else).+ const overlay = [...document.querySelectorAll<HTMLElement>("[data-escape-closes]")].some(shown);+ if (activeDialog() || overlay) return;if (window.history.length > 1) {handled();window.history.back();