Compare commits
6
Commits
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -87,15 +87,34 @@ export default function AppLayout() {
|
||||
<Stack.Screen
|
||||
name="settings"
|
||||
options={{
|
||||
headerShown: Platform.OS === "android",
|
||||
// iOS gets a native header with a close button; Android
|
||||
// draws its own title bar in the screen.
|
||||
headerShown: Platform.OS === "ios",
|
||||
title: "Settings",
|
||||
headerLargeTitle: false,
|
||||
headerTransparent: false,
|
||||
headerShadowVisible: false,
|
||||
headerStyle: { backgroundColor: "#000" },
|
||||
// Matches the inline title size of Apple Music's settings.
|
||||
headerTitleStyle: { fontSize: 20, fontWeight: "700" },
|
||||
presentation:
|
||||
Platform.OS === "ios" ? "modal" : "fullScreenModal",
|
||||
animation: "slide_from_bottom",
|
||||
gestureEnabled: true,
|
||||
gestureDirection: "vertical",
|
||||
}}
|
||||
/>
|
||||
>
|
||||
{/* Stack.Toolbar forces the header on, so keep it iOS-only. */}
|
||||
{Platform.OS === "ios" ? (
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Button
|
||||
icon="xmark"
|
||||
accessibilityLabel="Close settings"
|
||||
onPress={() => router.back()}
|
||||
/>
|
||||
</Stack.Toolbar>
|
||||
) : null}
|
||||
</Stack.Screen>
|
||||
<Stack.Screen
|
||||
name="create-account"
|
||||
options={{
|
||||
|
||||
@@ -1,16 +1 @@
|
||||
import { Platform } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import SettingsScreen from "./(tabs)/home/settings"
|
||||
|
||||
export default function Settings() {
|
||||
if (Platform.OS !== "android") return <SettingsScreen />
|
||||
return (
|
||||
<SafeAreaView
|
||||
edges={["bottom", "left", "right"]}
|
||||
style={{ flex: 1, backgroundColor: "#000" }}
|
||||
>
|
||||
<SettingsScreen />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
export { default } from "./(tabs)/home/settings"
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Button, Host } from "@expo/ui/swift-ui"
|
||||
import {
|
||||
buttonBorderShape,
|
||||
buttonStyle,
|
||||
controlSize,
|
||||
labelStyle,
|
||||
} from "@expo/ui/swift-ui/modifiers"
|
||||
|
||||
/** A native SwiftUI glass "+" button, matching the iOS header close button. */
|
||||
export function AddButton({
|
||||
label,
|
||||
onPress,
|
||||
}: {
|
||||
label: string
|
||||
onPress: () => void
|
||||
}) {
|
||||
return (
|
||||
<Host matchContents>
|
||||
<Button
|
||||
label={label}
|
||||
systemImage="plus"
|
||||
onPress={onPress}
|
||||
modifiers={[
|
||||
labelStyle("iconOnly"),
|
||||
buttonStyle("glass"),
|
||||
buttonBorderShape("circle"),
|
||||
controlSize("large"),
|
||||
]}
|
||||
/>
|
||||
</Host>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Pressable } from "react-native"
|
||||
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
|
||||
/** A plain "+" icon button. iOS uses a native SwiftUI button instead. */
|
||||
export function AddButton({
|
||||
label,
|
||||
onPress,
|
||||
}: {
|
||||
label: string
|
||||
onPress: () => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={label}
|
||||
hitSlop={8}
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
|
||||
>
|
||||
<Ionicons name="add" size={32} color={colors.foreground} />
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
memo,
|
||||
type ComponentType,
|
||||
type ReactElement,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react"
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import {
|
||||
Pressable,
|
||||
ScrollView,
|
||||
@@ -15,11 +6,14 @@ import {
|
||||
Text,
|
||||
View,
|
||||
type ScrollViewInstance,
|
||||
type ViewProps,
|
||||
} from "react-native"
|
||||
import MaskedViewClass from "@react-native-masked-view/masked-view"
|
||||
import Animated, {
|
||||
cancelAnimation,
|
||||
Easing,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withSequence,
|
||||
withTiming,
|
||||
type SharedValue,
|
||||
} from "react-native-reanimated"
|
||||
|
||||
@@ -28,7 +22,7 @@ import {
|
||||
usePlaybackProgress,
|
||||
usePlaybackQueue,
|
||||
} from "@/contexts/playback"
|
||||
import { useLyricsTime, usePlaybackClock } from "@/hooks/use-lyrics"
|
||||
import { useLyricsTime } from "@/hooks/use-lyrics"
|
||||
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||
import {
|
||||
activeLineIndex,
|
||||
@@ -37,21 +31,12 @@ import {
|
||||
type Lyrics,
|
||||
} from "@otunes/convex/client/lyrics"
|
||||
|
||||
// The package's class typings predate React 19's; this is its documented API.
|
||||
const MaskedView = MaskedViewClass as unknown as ComponentType<
|
||||
ViewProps & { maskElement: ReactElement }
|
||||
>
|
||||
|
||||
/** How long a manual scroll keeps the view from following the song. */
|
||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||
/** Where the playing line sits, as a share of the view's height from the top. */
|
||||
const ACTIVE_LINE_POSITION = 0.12
|
||||
/** Blur radius by distance from the playing line; farther lines share the last. */
|
||||
const LINE_BLUR = [0, 1, 2, 3]
|
||||
/** Opacity of lines other than the one playing. */
|
||||
const INACTIVE_LINE_OPACITY = 0.35
|
||||
/** How long a line takes to brighten, dim, or change blur. */
|
||||
const LINE_FADE_MS = 300
|
||||
|
||||
/**
|
||||
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
||||
@@ -92,7 +77,6 @@ function LyricsLines({
|
||||
const { isPlaying } = usePlaybackQueue()
|
||||
const { seekTo, setIsPlaying } = usePlaybackActions()
|
||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||
const clock = usePlaybackClock(currentTime, isPlaying)
|
||||
const active = activeLineIndex(lyrics, time)
|
||||
const synced = lyrics.synced !== "none"
|
||||
const scrollRef = useRef<ScrollViewInstance>(null)
|
||||
@@ -186,7 +170,8 @@ function LyricsLines({
|
||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||
}
|
||||
active={index === active}
|
||||
clock={clock}
|
||||
time={index === active ? time : null}
|
||||
isPlaying={isPlaying}
|
||||
colors={colors}
|
||||
textStyle={lineStyle}
|
||||
onSelect={playFrom}
|
||||
@@ -214,16 +199,17 @@ function LyricsLines({
|
||||
}
|
||||
|
||||
/**
|
||||
* One timed line, laid out word by word whether or not it is playing, so it
|
||||
* never re-wraps. It fades and blurs by its `distance` from the playing line,
|
||||
* and only the playing line's words fill.
|
||||
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||
* playing line gets the time, so the others skip re-rendering as the song
|
||||
* plays.
|
||||
*/
|
||||
const SyncedLine = memo(function SyncedLine({
|
||||
index,
|
||||
line,
|
||||
distance,
|
||||
active,
|
||||
clock,
|
||||
time,
|
||||
isPlaying,
|
||||
colors,
|
||||
textStyle,
|
||||
onSelect,
|
||||
@@ -233,100 +219,140 @@ const SyncedLine = memo(function SyncedLine({
|
||||
line: LyricLine
|
||||
distance: number
|
||||
active: boolean
|
||||
clock: SharedValue<number>
|
||||
time: number | null
|
||||
isPlaying: boolean
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
onSelect: (seconds: number) => void
|
||||
onLayoutY: (index: number, y: number) => void
|
||||
}) {
|
||||
const wordStyle = [styles.lineText, textStyle, { color: colors.foreground }]
|
||||
const blur = LINE_BLUR[distance]
|
||||
return (
|
||||
<Pressable
|
||||
onPress={() => onSelect(line.start ?? 0)}
|
||||
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
||||
accessibilityRole="button"
|
||||
accessibilityHint="Plays from this line"
|
||||
style={styles.line}
|
||||
style={[styles.line, blur > 0 && { filter: [{ blur }] }]}
|
||||
>
|
||||
<Animated.View
|
||||
style={{
|
||||
opacity: active ? 1 : INACTIVE_LINE_OPACITY,
|
||||
filter: [{ blur: LINE_BLUR[distance] }],
|
||||
transitionProperty: ["opacity", "filter"],
|
||||
transitionDuration: LINE_FADE_MS,
|
||||
}}
|
||||
>
|
||||
{line.words ? (
|
||||
<View
|
||||
style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}
|
||||
>
|
||||
{line.words.map((word, wordIndex) =>
|
||||
active ? (
|
||||
<FilledWord
|
||||
key={wordIndex}
|
||||
word={word}
|
||||
clock={clock}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
) : (
|
||||
<Text key={wordIndex} style={wordStyle}>
|
||||
{word.text.trim()}
|
||||
</Text>
|
||||
)
|
||||
)}
|
||||
</View>
|
||||
) : (
|
||||
<Text style={wordStyle}>{line.text}</Text>
|
||||
)}
|
||||
</Animated.View>
|
||||
{active && line.words && time !== null ? (
|
||||
<FilledWords
|
||||
words={line.words}
|
||||
time={time}
|
||||
isPlaying={isPlaying}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
) : (
|
||||
<Text
|
||||
style={[
|
||||
styles.lineText,
|
||||
textStyle,
|
||||
{
|
||||
color:
|
||||
active && !line.words
|
||||
? colors.foreground
|
||||
: colors.lyricsInactive,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{line.text}
|
||||
</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* A word of the playing line, filled from dim to bright with a soft edge as
|
||||
* it is sung: a gradient 2.5 times its width slides under the word's
|
||||
* shape, like the web panel's.
|
||||
* The playing line's words, each wiping from dim to bright as it is sung.
|
||||
* Reanimated runs the wipe; playback updates only re-anchor it.
|
||||
*/
|
||||
function FilledWords({
|
||||
words,
|
||||
time,
|
||||
isPlaying,
|
||||
colors,
|
||||
textStyle,
|
||||
}: {
|
||||
words: LyricWord[]
|
||||
time: number
|
||||
isPlaying: boolean
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
}) {
|
||||
const sung = useSharedValue(time)
|
||||
const end = words.at(-1)?.end ?? time
|
||||
|
||||
useEffect(() => {
|
||||
cancelAnimation(sung)
|
||||
// Jump to the reported time first, so the wipe never runs from a stale one.
|
||||
sung.value =
|
||||
isPlaying && end > time
|
||||
? withSequence(
|
||||
withTiming(time, { duration: 0 }),
|
||||
withTiming(end, {
|
||||
duration: (end - time) * 1000,
|
||||
easing: Easing.linear,
|
||||
})
|
||||
)
|
||||
: time
|
||||
}, [sung, time, isPlaying, end])
|
||||
|
||||
return (
|
||||
<View style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}>
|
||||
{words.map((word, index) => (
|
||||
<FilledWord
|
||||
key={index}
|
||||
word={word}
|
||||
sung={sung}
|
||||
colors={colors}
|
||||
textStyle={textStyle}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function FilledWord({
|
||||
word,
|
||||
clock,
|
||||
sung,
|
||||
colors,
|
||||
textStyle,
|
||||
}: {
|
||||
word: LyricWord
|
||||
clock: SharedValue<number>
|
||||
sung: SharedValue<number>
|
||||
colors: NowPlayingColors
|
||||
textStyle: { fontSize: number; lineHeight: number }
|
||||
}) {
|
||||
const [width, setWidth] = useState(0)
|
||||
const text = word.text.trim()
|
||||
const slide = useAnimatedStyle(() => {
|
||||
const wipe = useAnimatedStyle(() => {
|
||||
const progress =
|
||||
(clock.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||
const sung = Math.min(Math.max(progress, 0), 1)
|
||||
// -60% of the gradient's width shows its dim end; 0% its bright one.
|
||||
return { transform: [{ translateX: `${-60 * (1 - sung)}%` }] }
|
||||
(sung.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||
return { width: width * Math.min(Math.max(progress, 0), 1) }
|
||||
})
|
||||
|
||||
return (
|
||||
<MaskedView
|
||||
maskElement={
|
||||
<Text style={[styles.lineText, textStyle, styles.mask]}>{text}</Text>
|
||||
}
|
||||
>
|
||||
{/* Sizes the word; the mask draws it. */}
|
||||
<Text style={[styles.lineText, textStyle, styles.hidden]}>{text}</Text>
|
||||
<Animated.View
|
||||
style={[
|
||||
styles.fillGradient,
|
||||
{
|
||||
backgroundImage: `linear-gradient(90deg, ${colors.foreground} 40%, ${colors.lyricsUnsung} 60%)`,
|
||||
},
|
||||
slide,
|
||||
]}
|
||||
/>
|
||||
</MaskedView>
|
||||
<View>
|
||||
<Text
|
||||
style={[styles.lineText, textStyle, { color: colors.lyricsUnsung }]}
|
||||
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
||||
>
|
||||
{text}
|
||||
</Text>
|
||||
<Animated.View style={[styles.wipe, wipe]}>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={[
|
||||
styles.lineText,
|
||||
textStyle,
|
||||
{ color: colors.foreground, width },
|
||||
]}
|
||||
>
|
||||
{text}
|
||||
</Text>
|
||||
</Animated.View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -337,14 +363,12 @@ const styles = StyleSheet.create({
|
||||
line: { paddingVertical: 9 },
|
||||
lineText: { fontWeight: "800" },
|
||||
words: { flexDirection: "row", flexWrap: "wrap" },
|
||||
mask: { color: "black" },
|
||||
hidden: { opacity: 0 },
|
||||
fillGradient: {
|
||||
wipe: {
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
width: "250%",
|
||||
overflow: "hidden",
|
||||
},
|
||||
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||
stanzaGap: { height: 18 },
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
writeRememberedDownloadQuality,
|
||||
} from "@/lib/downloads"
|
||||
import { loadPlaybackSongs } from "@/lib/playback-files"
|
||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
||||
import type { ServerConfig } from "@/lib/server-config"
|
||||
import { showError } from "@/lib/toast"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
@@ -239,44 +238,36 @@ function DownloadQualityPopup({
|
||||
>
|
||||
{pending?.target.title}
|
||||
</Text>
|
||||
{pending?.response.options
|
||||
.filter((option) => downloadQualitySupported(option.quality))
|
||||
.map((option) => (
|
||||
<Pressable
|
||||
key={option.quality}
|
||||
accessibilityRole="button"
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => onPick(option.quality, remember)}
|
||||
>
|
||||
<View style={styles.rowText}>
|
||||
{option.quality === "lossless" ||
|
||||
option.quality === "atmos" ? (
|
||||
<AudioFormatBadge
|
||||
format={option.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
) : (
|
||||
<Text
|
||||
style={[styles.label, { color: colors.foreground }]}
|
||||
>
|
||||
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
||||
</Text>
|
||||
)}
|
||||
<Text
|
||||
style={{ color: colors.mutedForeground, fontSize: 12 }}
|
||||
>
|
||||
{optionDetail(option, songCount)}
|
||||
{pending?.response.options.map((option) => (
|
||||
<Pressable
|
||||
key={option.quality}
|
||||
accessibilityRole="button"
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => onPick(option.quality, remember)}
|
||||
>
|
||||
<View style={styles.rowText}>
|
||||
{option.quality === "lossless" ||
|
||||
option.quality === "atmos" ? (
|
||||
<AudioFormatBadge
|
||||
format={option.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
) : (
|
||||
<Text style={[styles.label, { color: colors.foreground }]}>
|
||||
{DOWNLOAD_QUALITY_LABELS[option.quality]}
|
||||
</Text>
|
||||
</View>
|
||||
<Text
|
||||
style={[styles.size, { color: colors.mutedForeground }]}
|
||||
>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
)}
|
||||
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
||||
{optionDetail(option, songCount)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={styles.rememberRow}>
|
||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||
Remember my choice
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
import { File } from "expo-file-system"
|
||||
import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
} from "react"
|
||||
import {
|
||||
cancelAnimation,
|
||||
Easing,
|
||||
useSharedValue,
|
||||
withSequence,
|
||||
withTiming,
|
||||
} from "react-native-reanimated"
|
||||
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
||||
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
@@ -120,39 +107,3 @@ export function useLyricsTime(
|
||||
? advanced.time
|
||||
: currentTime
|
||||
}
|
||||
|
||||
/** How far the clock may drift from the player before it is reset. */
|
||||
const CLOCK_DRIFT_SECONDS = 0.15
|
||||
/** How far ahead the clock runs on its own; progress updates come long before. */
|
||||
const CLOCK_RUN_SECONDS = 3600
|
||||
|
||||
/**
|
||||
* Playback time in seconds on the UI thread, running smoothly between the
|
||||
* player's progress updates. It is reset only when it drifts, so animations
|
||||
* driven by it never restart mid-word.
|
||||
*/
|
||||
export function usePlaybackClock(currentTime: number, isPlaying: boolean) {
|
||||
const clock = useSharedValue(currentTime)
|
||||
const running = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPlaying) {
|
||||
running.current = false
|
||||
cancelAnimation(clock)
|
||||
clock.value = currentTime
|
||||
return
|
||||
}
|
||||
const drift = Math.abs(clock.value - currentTime)
|
||||
if (running.current && drift < CLOCK_DRIFT_SECONDS) return
|
||||
running.current = true
|
||||
clock.value = withSequence(
|
||||
withTiming(currentTime, { duration: 0 }),
|
||||
withTiming(currentTime + CLOCK_RUN_SECONDS, {
|
||||
duration: CLOCK_RUN_SECONDS * 1000,
|
||||
easing: Easing.linear,
|
||||
})
|
||||
)
|
||||
}, [clock, currentTime, isPlaying])
|
||||
|
||||
return clock
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
type DownloadQuality,
|
||||
} from "@otunes/convex/download-quality"
|
||||
import { getAuthCookieHeader } from "@/lib/auth-cookies"
|
||||
import { downloadQualitySupported } from "@/lib/playback-capabilities"
|
||||
import type { ServerConfig } from "@/lib/server-config"
|
||||
|
||||
const REMEMBERED_QUALITY_KEY = "otunes.download-quality"
|
||||
@@ -299,10 +298,9 @@ export function downloadedCoverUri(url: string) {
|
||||
|
||||
export async function readRememberedDownloadQuality() {
|
||||
try {
|
||||
const quality = parseDownloadQuality(
|
||||
return parseDownloadQuality(
|
||||
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
||||
)
|
||||
return quality && downloadQualitySupported(quality) ? quality : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ export type NowPlayingColors = {
|
||||
selected: string
|
||||
selectedForeground: string
|
||||
highlight: string
|
||||
/** Lyrics lines other than the one playing. */
|
||||
lyricsInactive: string
|
||||
/** Words of the playing line not yet sung. */
|
||||
lyricsUnsung: string
|
||||
isDark: boolean
|
||||
@@ -30,6 +32,7 @@ export function nowPlayingColors(palette: CoverPalette): NowPlayingColors {
|
||||
selected: withAlpha(foreground, 0.8),
|
||||
selectedForeground: palette.background,
|
||||
highlight: withAlpha(foreground, 0.1),
|
||||
lyricsInactive: withAlpha(foreground, 0.35),
|
||||
lyricsUnsung: withAlpha(foreground, 0.55),
|
||||
isDark: palette.isDark,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { Platform } from "react-native"
|
||||
|
||||
import {
|
||||
DOWNLOAD_QUALITIES,
|
||||
type DownloadQuality,
|
||||
} from "@otunes/convex/download-quality"
|
||||
|
||||
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
|
||||
export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
|
||||
@@ -12,13 +7,3 @@ export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
export function atmosEnabled(user: { preferAtmos?: boolean }) {
|
||||
return dolbyAtmosSupported && (user.preferAtmos ?? false)
|
||||
}
|
||||
|
||||
/** Whether this device may download in a quality. Android cannot download Atmos. */
|
||||
export function downloadQualitySupported(quality: DownloadQuality) {
|
||||
return quality !== "atmos" || dolbyAtmosSupported
|
||||
}
|
||||
|
||||
/** Download qualities this device offers, lowest first. */
|
||||
export const deviceDownloadQualities = DOWNLOAD_QUALITIES.filter(
|
||||
downloadQualitySupported
|
||||
)
|
||||
@@ -20,7 +20,6 @@
|
||||
"@otunes/convex": "workspace:*",
|
||||
"@react-native-async-storage/async-storage": "2.2.0",
|
||||
"@react-native-community/slider": "5.2.1",
|
||||
"@react-native-masked-view/masked-view": "0.3.2",
|
||||
"@react-native/metro-config": "0.88.0",
|
||||
"convex": "^1.40.0",
|
||||
"expo": "~58.0.17",
|
||||
|
||||
@@ -39,10 +39,9 @@ const ASK_EVERY_TIME = "ask"
|
||||
|
||||
/** Shades of the text color, darkest for the smallest files. */
|
||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||
low: 0.2,
|
||||
medium: 0.35,
|
||||
high: 0.5,
|
||||
lossless: 0.75,
|
||||
medium: 0.25,
|
||||
high: 0.45,
|
||||
lossless: 0.7,
|
||||
atmos: 1,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
|
||||
|
||||
/** Qualities a listener can pick when downloading, lowest first. */
|
||||
export const DOWNLOAD_QUALITIES = [
|
||||
"low",
|
||||
"medium",
|
||||
"high",
|
||||
"lossless",
|
||||
@@ -12,7 +11,6 @@ export const DOWNLOAD_QUALITIES = [
|
||||
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
||||
|
||||
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
||||
low: "Low",
|
||||
medium: "Medium",
|
||||
high: "High",
|
||||
lossless: "Lossless",
|
||||
@@ -20,14 +18,12 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
||||
}
|
||||
|
||||
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
||||
low: "AAC 64 kbps",
|
||||
medium: "AAC 128 kbps",
|
||||
high: "AAC 256 kbps",
|
||||
lossless: "ALAC or FLAC",
|
||||
atmos: "Spatial audio",
|
||||
}
|
||||
|
||||
const LOW_KBPS = 64
|
||||
const MEDIUM_KBPS = 128
|
||||
const HIGH_KBPS = 256
|
||||
|
||||
@@ -58,14 +54,13 @@ function highPlan(files: Record<string, unknown>): DownloadPlan {
|
||||
|
||||
/**
|
||||
* Picks the file for one song. Lossless and Dolby Atmos fall back to High when
|
||||
* the song lacks them, and Low and Medium are always transcoded.
|
||||
* the song lacks them, and Medium is always transcoded.
|
||||
*/
|
||||
export function downloadPlan(
|
||||
files: Record<string, unknown>,
|
||||
quality: DownloadQuality
|
||||
): DownloadPlan {
|
||||
switch (quality) {
|
||||
case "low":
|
||||
case "medium":
|
||||
return {
|
||||
quality,
|
||||
@@ -75,7 +70,7 @@ export function downloadPlan(
|
||||
: "normal" in files
|
||||
? "normal"
|
||||
: "atmos",
|
||||
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
||||
kbps: MEDIUM_KBPS,
|
||||
}
|
||||
case "high":
|
||||
return highPlan(files)
|
||||
@@ -89,7 +84,7 @@ export function downloadPlan(
|
||||
|
||||
/**
|
||||
* The download quality holding the same audio a stream plan plays, so a
|
||||
* download can stand in for streaming.
|
||||
* download can stand in for streaming. Low has no download equivalent.
|
||||
*/
|
||||
export function streamDownloadQuality(
|
||||
plan: PlaybackStreamPlan
|
||||
@@ -100,7 +95,6 @@ export function streamDownloadQuality(
|
||||
}
|
||||
if (plan.kbps === HIGH_KBPS) return "high"
|
||||
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
||||
if (plan.kbps === LOW_KBPS) return "low"
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -135,7 +129,6 @@ export function downloadOptions(
|
||||
).length
|
||||
if (
|
||||
fallbackCount === songs.length &&
|
||||
quality !== "low" &&
|
||||
quality !== "medium" &&
|
||||
quality !== "high"
|
||||
) {
|
||||
|
||||
Generated
-3
@@ -279,9 +279,6 @@ importers:
|
||||
'@react-native-community/slider':
|
||||
specifier: 5.2.1
|
||||
version: 5.2.1(patch_hash=73deacaea9aae000a42050d343517da9e16e736e92a4fff3f61f81dba093a1c4)
|
||||
'@react-native-masked-view/masked-view':
|
||||
specifier: 0.3.2
|
||||
version: 0.3.2(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.0)(supports-color@8.1.1))(react@19.3.0)
|
||||
'@react-native/metro-config':
|
||||
specifier: 0.88.0
|
||||
version: 0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1)
|
||||
|
||||
Reference in new issue
Block a user