Compare commits
3
Commits
No files matched your search
@@ -1,4 +1,8 @@
|
||||
import { atmosEnabled, dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import {
|
||||
atmosEnabled,
|
||||
deviceDownloadQualities,
|
||||
dolbyAtmosSupported,
|
||||
} from "@/lib/playback-capabilities"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { useAction, useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
@@ -25,7 +29,6 @@ import {
|
||||
writeRememberedDownloadQuality,
|
||||
} from "@/lib/downloads"
|
||||
import {
|
||||
DOWNLOAD_QUALITIES,
|
||||
DOWNLOAD_QUALITY_DETAILS,
|
||||
DOWNLOAD_QUALITY_LABELS,
|
||||
formatBytes,
|
||||
@@ -450,9 +453,10 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
|
||||
/** Shades of the text color, faintest for the smallest files. */
|
||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||
medium: 0.25,
|
||||
high: 0.45,
|
||||
lossless: 0.7,
|
||||
low: 0.2,
|
||||
medium: 0.35,
|
||||
high: 0.5,
|
||||
lossless: 0.75,
|
||||
atmos: 1,
|
||||
}
|
||||
|
||||
@@ -507,7 +511,7 @@ function RememberedQualityCard() {
|
||||
detail: string
|
||||
}[] = [
|
||||
{ value: null, label: "Ask every time", detail: "Choose when downloading" },
|
||||
...DOWNLOAD_QUALITIES.map((quality) => ({
|
||||
...deviceDownloadQualities.map((quality) => ({
|
||||
value: quality,
|
||||
label: DOWNLOAD_QUALITY_LABELS[quality],
|
||||
detail: DOWNLOAD_QUALITY_DETAILS[quality],
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
useAndroidTabPalette,
|
||||
useAndroidTabHasArtworkPalette,
|
||||
} from "@/contexts/android-tab-theme"
|
||||
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { NativeTabs } from "expo-router/native-tabs"
|
||||
import { useRouter } from "expo-router"
|
||||
@@ -166,20 +163,10 @@ function MiniPlayerContent({
|
||||
|
||||
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
|
||||
const palette = useAndroidTabPalette()
|
||||
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
|
||||
|
||||
return (
|
||||
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
|
||||
{children}
|
||||
{hasArtworkPalette ? (
|
||||
<View
|
||||
style={[
|
||||
styles.separator,
|
||||
styles.topBorder,
|
||||
{ backgroundColor: palette.secondaryForeground },
|
||||
]}
|
||||
/>
|
||||
) : null}
|
||||
<View
|
||||
style={[
|
||||
styles.separator,
|
||||
@@ -267,7 +254,6 @@ const styles = StyleSheet.create({
|
||||
height: 1,
|
||||
zIndex: 1,
|
||||
},
|
||||
topBorder: { top: 0 },
|
||||
bottomBorder: { bottom: 0 },
|
||||
content: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -34,6 +34,7 @@ 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"
|
||||
@@ -238,36 +239,44 @@ function DownloadQualityPopup({
|
||||
>
|
||||
{pending?.target.title}
|
||||
</Text>
|
||||
{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]}
|
||||
{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)}
|
||||
</Text>
|
||||
)}
|
||||
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
|
||||
{optionDetail(option, songCount)}
|
||||
</View>
|
||||
<Text
|
||||
style={[styles.size, { color: colors.mutedForeground }]}
|
||||
>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</View>
|
||||
<Text style={[styles.size, { color: colors.mutedForeground }]}>
|
||||
{option.estimated ? "~" : ""}
|
||||
{formatBytes(option.bytes)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={styles.rememberRow}>
|
||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||
Remember my choice
|
||||
|
||||
@@ -16,6 +16,7 @@ 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"
|
||||
@@ -298,9 +299,10 @@ export function downloadedCoverUri(url: string) {
|
||||
|
||||
export async function readRememberedDownloadQuality() {
|
||||
try {
|
||||
return parseDownloadQuality(
|
||||
const quality = parseDownloadQuality(
|
||||
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
|
||||
)
|
||||
return quality && downloadQualitySupported(quality) ? quality : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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"
|
||||
|
||||
@@ -7,3 +12,13 @@ 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
|
||||
)
|
||||
@@ -39,9 +39,10 @@ const ASK_EVERY_TIME = "ask"
|
||||
|
||||
/** Shades of the text color, darkest for the smallest files. */
|
||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||
medium: 0.25,
|
||||
high: 0.45,
|
||||
lossless: 0.7,
|
||||
low: 0.2,
|
||||
medium: 0.35,
|
||||
high: 0.5,
|
||||
lossless: 0.75,
|
||||
atmos: 1,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
|
||||
|
||||
/** Qualities a listener can pick when downloading, lowest first. */
|
||||
export const DOWNLOAD_QUALITIES = [
|
||||
"low",
|
||||
"medium",
|
||||
"high",
|
||||
"lossless",
|
||||
@@ -11,6 +12,7 @@ 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",
|
||||
@@ -18,12 +20,14 @@ 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
|
||||
|
||||
@@ -54,13 +58,14 @@ 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 Medium is always transcoded.
|
||||
* the song lacks them, and Low and Medium are always transcoded.
|
||||
*/
|
||||
export function downloadPlan(
|
||||
files: Record<string, unknown>,
|
||||
quality: DownloadQuality
|
||||
): DownloadPlan {
|
||||
switch (quality) {
|
||||
case "low":
|
||||
case "medium":
|
||||
return {
|
||||
quality,
|
||||
@@ -70,7 +75,7 @@ export function downloadPlan(
|
||||
: "normal" in files
|
||||
? "normal"
|
||||
: "atmos",
|
||||
kbps: MEDIUM_KBPS,
|
||||
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
||||
}
|
||||
case "high":
|
||||
return highPlan(files)
|
||||
@@ -84,7 +89,7 @@ export function downloadPlan(
|
||||
|
||||
/**
|
||||
* The download quality holding the same audio a stream plan plays, so a
|
||||
* download can stand in for streaming. Low has no download equivalent.
|
||||
* download can stand in for streaming.
|
||||
*/
|
||||
export function streamDownloadQuality(
|
||||
plan: PlaybackStreamPlan
|
||||
@@ -95,6 +100,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -129,6 +135,7 @@ export function downloadOptions(
|
||||
).length
|
||||
if (
|
||||
fallbackCount === songs.length &&
|
||||
quality !== "low" &&
|
||||
quality !== "medium" &&
|
||||
quality !== "high"
|
||||
) {
|
||||
|
||||
Reference in new issue
Block a user