From 578e72b338cc803c47382d397e5647e7c4c0fc1d Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 23 Jun 2026 23:17:46 -0400 Subject: [PATCH] feat(mobile): lockscreen controls --- apps/mobile/app.json | 7 +------ apps/mobile/contexts/playback.tsx | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/mobile/app.json b/apps/mobile/app.json index 810f791..f02ab5d 100644 --- a/apps/mobile/app.json +++ b/apps/mobile/app.json @@ -9,11 +9,7 @@ "ios": { "supportsTablet": true, "bundleIdentifier": "com.abunchofknowitalls.otunes", - "infoPlist": { - "UIBackgroundModes": [ - "audio" - ] - } + "infoPlist": {} }, "android": { "package": "com.abunchofknowitalls.otunes", @@ -25,7 +21,6 @@ [ "expo-audio", { - "microphonePermission": false, "enableBackgroundPlayback": true } ], diff --git a/apps/mobile/contexts/playback.tsx b/apps/mobile/contexts/playback.tsx index d165767..69ebd7d 100644 --- a/apps/mobile/contexts/playback.tsx +++ b/apps/mobile/contexts/playback.tsx @@ -1,6 +1,7 @@ import { createAudioPlayer, setAudioModeAsync, + type AudioMetadata, type AudioPlayer, type AudioStatus, } from "expo-audio" @@ -24,7 +25,7 @@ import type { BrowseSong } from "@otunes/convex/types" import { playbackStreamPlan } from "@otunes/convex/playback-stream" import { getAuthCookieHeader } from "@/lib/auth-cookies" import { showError } from "@/lib/toast" -import { songAudioSource } from "@/lib/urls" +import { albumCoverUrl, songAudioSource } from "@/lib/urls" type RepeatMode = "none" | "once" | "always" @@ -32,6 +33,18 @@ const PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS = 5 const VOLUME_STORAGE_KEY = "otunes:volume" const DEFAULT_VOLUME = 0.8 +function lockScreenMetadata( + song: BrowseSong, + serverUrl: string +): AudioMetadata { + return { + title: song.title, + artist: song.artist.name, + albumTitle: song.album.title, + artworkUrl: albumCoverUrl(serverUrl, song.album.id), + } +} + type PlaybackContextValue = { queueSongIds: Id<"songs">[] queueHistorySongIds: Id<"songs">[] @@ -143,6 +156,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) { const destroyPlayer = useCallback(() => { statusSubscriptionRef.current?.remove() statusSubscriptionRef.current = null + playerRef.current?.setActiveForLockScreen(false) playerRef.current?.remove() playerRef.current = null loadedSongKeyRef.current = null @@ -223,9 +237,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) { void setAudioModeAsync({ playsInSilentMode: true, shouldPlayInBackground: true, - interruptionMode: "duckOthers", - allowsRecording: false, - shouldRouteThroughEarpiece: false, + interruptionMode: "doNotMix", }) void AsyncStorage.getItem(VOLUME_STORAGE_KEY).then((stored) => { @@ -352,6 +364,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) { player.replace(source) player.volume = volume + player.setActiveForLockScreen( + true, + lockScreenMetadata(currentSong, config.serverUrl), + { showSeekForward: true, showSeekBackward: true } + ) if (isPlayingRef.current || autoPlayNextRef.current) { player.play()