feat(mobile): lockscreen controls
This commit is contained in:
1 parent
37c4348a9d
commit
578e72b338
2 files changed
+22
-10
No files matched your search
@@ -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
|
||||
}
|
||||
],
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user