Compare commits
10
Commits
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { useAction, useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import * as ImagePicker from "expo-image-picker"
|
||||
import { useState } from "react"
|
||||
import { router } from "expo-router"
|
||||
import {
|
||||
Platform,
|
||||
Pressable,
|
||||
@@ -374,7 +376,12 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
<SettingsCard title="Spatial Audio">
|
||||
<SwitchRow
|
||||
title="Prefer Dolby Atmos"
|
||||
subtitle="Use Atmos versions when they are available."
|
||||
subtitle={
|
||||
dolbyAtmosSupported
|
||||
? "Use Atmos versions when they are available."
|
||||
: "This device does not support Dolby Atmos playback."
|
||||
}
|
||||
disabled={!dolbyAtmosSupported}
|
||||
value={user.preferAtmos ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
@@ -459,7 +466,7 @@ function UsersSection({
|
||||
<SettingsCard title="Sign Up">
|
||||
<SwitchRow
|
||||
title="Disable account creation"
|
||||
subtitle="Stop people from registering themselves. Admins can still create accounts from the web app."
|
||||
subtitle="Stop people from registering themselves. Admins can still create accounts."
|
||||
value={appSettings?.disableAccountCreation ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void setDisableCreation({ disabled: checked }).catch(
|
||||
@@ -473,6 +480,10 @@ function UsersSection({
|
||||
title="People"
|
||||
subtitle="Manage who can access this server."
|
||||
>
|
||||
<Button
|
||||
title="Create account"
|
||||
onPress={() => router.push("/(app)/create-account")}
|
||||
/>
|
||||
<View style={styles.userList}>
|
||||
{users.map((user, index) => (
|
||||
<View
|
||||
@@ -636,10 +647,12 @@ function SwitchRow({
|
||||
subtitle,
|
||||
value,
|
||||
onValueChange,
|
||||
disabled,
|
||||
}: {
|
||||
title: string
|
||||
subtitle?: string
|
||||
value: boolean
|
||||
disabled?: boolean
|
||||
onValueChange: (checked: boolean) => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
@@ -656,6 +669,7 @@ function SwitchRow({
|
||||
</View>
|
||||
<Switch
|
||||
value={value}
|
||||
disabled={disabled}
|
||||
onValueChange={onValueChange}
|
||||
{...(Platform.OS === "android"
|
||||
? {
|
||||
|
||||
@@ -75,14 +75,25 @@ export default function AppLayout() {
|
||||
gestureDirection: "vertical",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="create-account"
|
||||
options={{
|
||||
title: "Create account",
|
||||
presentation: "modal",
|
||||
headerLargeTitle: false,
|
||||
headerTransparent: false,
|
||||
headerStyle: { backgroundColor: "#000" },
|
||||
headerTintColor: "#fff",
|
||||
contentStyle: { backgroundColor: "#000" },
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="player"
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation:
|
||||
Platform.OS === "ios"
|
||||
? "transparentModal"
|
||||
: "fullScreenModal",
|
||||
// Keep the library visible behind the custom swipe animation.
|
||||
presentation: "transparentModal",
|
||||
contentStyle: { backgroundColor: "transparent" },
|
||||
animation: "slide_from_bottom",
|
||||
gestureEnabled: true,
|
||||
gestureDirection: "vertical",
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import { useAction, useQuery } from "convex/react"
|
||||
import { ConvexError } from "convex/values"
|
||||
import { router, Stack } from "expo-router"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import {
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Switch,
|
||||
Text,
|
||||
View,
|
||||
} from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { toast } from "sonner-native"
|
||||
|
||||
import { Button, Input, LoadingView } from "@/components/ui/primitives"
|
||||
import { colors, spacing } from "@/lib/theme"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function CreateAccountScreen() {
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
const createUser = useAction(api.users.adminCreateUser)
|
||||
const [name, setName] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
const [password, setPassword] = useState("")
|
||||
const [isAdmin, setIsAdmin] = useState(false)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const pending = useRef(false)
|
||||
const mounted = useRef(true)
|
||||
|
||||
useEffect(() => {
|
||||
mounted.current = true
|
||||
return () => {
|
||||
mounted.current = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
async function handleCreate() {
|
||||
if (pending.current || !user?.isAdmin) return
|
||||
setError(null)
|
||||
if (!name.trim() || !email.trim().includes("@") || password.length < 8) {
|
||||
setError(
|
||||
"Enter a name, valid email, and password of at least 8 characters."
|
||||
)
|
||||
return
|
||||
}
|
||||
pending.current = true
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await createUser({
|
||||
name: name.trim(),
|
||||
email: email.trim().toLowerCase(),
|
||||
password,
|
||||
isAdmin,
|
||||
})
|
||||
toast.success("Account created")
|
||||
if (mounted.current) router.back()
|
||||
} catch (error) {
|
||||
if (!mounted.current) return
|
||||
setError(
|
||||
error instanceof ConvexError && typeof error.data === "string"
|
||||
? error.data
|
||||
: "Could not create account. Try again."
|
||||
)
|
||||
} finally {
|
||||
pending.current = false
|
||||
if (mounted.current) setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView edges={["bottom", "left", "right"]} style={styles.screen}>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
gestureEnabled: !submitting,
|
||||
}}
|
||||
/>
|
||||
{user === undefined ? (
|
||||
<LoadingView />
|
||||
) : !user?.isAdmin ? (
|
||||
<Text style={[styles.text, styles.message]}>
|
||||
Admin access required.
|
||||
</Text>
|
||||
) : (
|
||||
<KeyboardAvoidingView
|
||||
style={styles.screen}
|
||||
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
||||
keyboardVerticalOffset={Platform.OS === "ios" ? 100 : 0}
|
||||
>
|
||||
<ScrollView
|
||||
contentContainerStyle={styles.form}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="on-drag"
|
||||
>
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>Name</Text>
|
||||
<Input
|
||||
accessibilityLabel="Name"
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
autoCapitalize="words"
|
||||
autoComplete="off"
|
||||
editable={!submitting}
|
||||
style={styles.input}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>Email</Text>
|
||||
<Input
|
||||
accessibilityLabel="Email"
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
keyboardType="email-address"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoComplete="off"
|
||||
editable={!submitting}
|
||||
style={styles.input}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>Password</Text>
|
||||
<Input
|
||||
accessibilityLabel="Password"
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
secureTextEntry
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoComplete="new-password"
|
||||
placeholder="At least 8 characters"
|
||||
editable={!submitting}
|
||||
style={styles.input}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.row}>
|
||||
<Text style={styles.text}>Grant admin access</Text>
|
||||
<Switch
|
||||
accessibilityLabel="Grant admin access"
|
||||
trackColor={{
|
||||
false: colors.dark.muted,
|
||||
true: colors.dark.primary,
|
||||
}}
|
||||
thumbColor={colors.dark.foreground}
|
||||
value={isAdmin}
|
||||
onValueChange={setIsAdmin}
|
||||
disabled={submitting}
|
||||
/>
|
||||
</View>
|
||||
{error ? (
|
||||
<Text accessibilityRole="alert" style={styles.error}>
|
||||
{error}
|
||||
</Text>
|
||||
) : null}
|
||||
<Button
|
||||
title={submitting ? "Creating account…" : "Create account"}
|
||||
disabled={submitting}
|
||||
onPress={() => void handleCreate()}
|
||||
tint={{
|
||||
background: colors.dark.primary,
|
||||
foreground: colors.dark.primaryForeground,
|
||||
}}
|
||||
/>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
screen: { flex: 1, backgroundColor: "#000" },
|
||||
form: { padding: spacing.lg, gap: spacing.lg },
|
||||
field: { gap: spacing.sm },
|
||||
label: {
|
||||
color: colors.dark.mutedForeground,
|
||||
fontSize: 12,
|
||||
fontWeight: "600",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: 0.6,
|
||||
},
|
||||
text: { color: colors.dark.foreground, fontSize: 16, flexShrink: 1 },
|
||||
input: {
|
||||
backgroundColor: colors.dark.muted,
|
||||
color: colors.dark.foreground,
|
||||
borderColor: colors.dark.border,
|
||||
},
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
gap: spacing.md,
|
||||
minHeight: 48,
|
||||
},
|
||||
message: { padding: spacing.lg },
|
||||
error: { color: colors.dark.destructive, fontSize: 14, lineHeight: 20 },
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import { NavigationBar } from "expo-navigation-bar"
|
||||
import { MusicEntityView } from "@/components/music-entity-view"
|
||||
import { Stack, useRouter } from "expo-router"
|
||||
@@ -91,6 +92,7 @@ export default function PlayerScreen() {
|
||||
} = usePlayback()
|
||||
const { volume, setVolume, available: volumeAvailable } = useSystemVolume()
|
||||
const [showQueue, setShowQueue] = useState(false)
|
||||
const [isDismissing, setIsDismissing] = useState(false)
|
||||
const [stageHeight, setStageHeight] = useState(0)
|
||||
const [scrubTime, setScrubTime] = useState<number | null>(null)
|
||||
const user = useCachedQuery(api.auth.currentUser)
|
||||
@@ -103,7 +105,7 @@ export default function PlayerScreen() {
|
||||
? playbackFormat(
|
||||
playbackInfo.files,
|
||||
user.playbackQuality,
|
||||
user.preferAtmos ?? false
|
||||
dolbyAtmosSupported && (user.preferAtmos ?? false)
|
||||
)
|
||||
: null
|
||||
|
||||
@@ -162,6 +164,7 @@ export default function PlayerScreen() {
|
||||
event.translationY > DISMISS_DISTANCE ||
|
||||
event.velocityY > DISMISS_VELOCITY
|
||||
) {
|
||||
scheduleOnRN(setIsDismissing, true)
|
||||
dismissY.value = withTiming(
|
||||
windowHeight,
|
||||
{ duration: 220 },
|
||||
@@ -221,7 +224,11 @@ export default function PlayerScreen() {
|
||||
{Platform.OS === "android" ? (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{ statusBarStyle: colors.isDark ? "light" : "dark" }}
|
||||
options={{
|
||||
statusBarStyle: colors.isDark ? "light" : "dark",
|
||||
// The swipe already animates the player offscreen.
|
||||
animation: isDismissing ? "none" : "slide_from_bottom",
|
||||
}}
|
||||
/>
|
||||
<NavigationBar style={colors.isDark ? "light" : "dark"} />
|
||||
</>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import {
|
||||
createAudioPlaylist,
|
||||
setAudioModeAsync,
|
||||
@@ -313,7 +314,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
? JSON.stringify([
|
||||
user._id,
|
||||
user.playbackQuality,
|
||||
user.preferAtmos ?? false,
|
||||
dolbyAtmosSupported && (user.preferAtmos ?? false),
|
||||
])
|
||||
: ""
|
||||
|
||||
@@ -625,7 +626,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
if (!isCurrentLoad()) return
|
||||
|
||||
const loadKey = `${user.playbackQuality}:${user.preferAtmos ?? false}:${cookieHeader}`
|
||||
const loadKey = `${user.playbackQuality}:${dolbyAtmosSupported && (user.preferAtmos ?? false)}:${cookieHeader}`
|
||||
const needsRebuild =
|
||||
loadedLoadKeyRef.current !== loadKey ||
|
||||
nativePlaylistNeedsRebuild(
|
||||
@@ -667,7 +668,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const plan = playbackStreamPlan(
|
||||
song.files,
|
||||
user.playbackQuality,
|
||||
user.preferAtmos ?? false
|
||||
dolbyAtmosSupported && (user.preferAtmos ?? false)
|
||||
)
|
||||
sources.set(
|
||||
song.id,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { requireOptionalNativeModule } from "expo"
|
||||
import { Platform } from "react-native"
|
||||
|
||||
// E-AC-3 support varies by Android device. Older native builds fail closed.
|
||||
function supportsDolbyAtmos(): boolean {
|
||||
if (Platform.OS === "ios") return true
|
||||
if (Platform.OS !== "android") return false
|
||||
try {
|
||||
return (
|
||||
requireOptionalNativeModule<{
|
||||
supportsDolbyAtmos?: () => boolean
|
||||
}>("AudioOutput")?.supportsDolbyAtmos?.() ?? false
|
||||
)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const dolbyAtmosSupported = supportsDolbyAtmos()
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Platform } from "react-native"
|
||||
import type { AudioSource } from "expo-audio"
|
||||
|
||||
export type PlaybackQuality = "low" | "medium" | "high" | "lossless"
|
||||
@@ -50,6 +51,7 @@ export function songPlayUrl(
|
||||
preferAtmos: boolean | undefined
|
||||
) {
|
||||
const params = new URLSearchParams()
|
||||
if (Platform.OS === "ios") params.set("losslessFormat", "alac")
|
||||
if (quality) params.set("quality", quality)
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
|
||||
+11
@@ -1,5 +1,6 @@
|
||||
package expo.modules.audiooutput
|
||||
|
||||
import android.media.MediaCodecList
|
||||
import android.os.Build
|
||||
import androidx.mediarouter.app.SystemOutputSwitcherDialogController
|
||||
import expo.modules.kotlin.functions.Queues
|
||||
@@ -10,6 +11,16 @@ class AudioOutputModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("AudioOutput")
|
||||
|
||||
Function("supportsDolbyAtmos") {
|
||||
// Library Atmos tracks use E-AC-3. ExoPlayer needs a device decoder.
|
||||
MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos.any { codec ->
|
||||
!codec.isEncoder && codec.supportedTypes.any { type ->
|
||||
type.equals("audio/eac3", ignoreCase = true) ||
|
||||
type.equals("audio/eac3-joc", ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AsyncFunction("showPicker") {
|
||||
val activity = appContext.currentActivity
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || activity == null) {
|
||||
|
||||
@@ -7,24 +7,37 @@ public class AudioOutputModule: Module {
|
||||
|
||||
View(AudioOutputView.self) {
|
||||
Prop("tint") { (view: AudioOutputView, color: UIColor) in
|
||||
view.picker.tintColor = color
|
||||
view.icon.tintColor = color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class AudioOutputView: ExpoView {
|
||||
let picker = AVRoutePickerView()
|
||||
private let picker = AVRoutePickerView()
|
||||
let icon = UIImageView(
|
||||
image: UIImage(
|
||||
systemName: "airplay.audio",
|
||||
withConfiguration: UIImage.SymbolConfiguration(pointSize: 27, weight: .semibold)
|
||||
)
|
||||
)
|
||||
|
||||
required init(appContext: AppContext? = nil) {
|
||||
super.init(appContext: appContext)
|
||||
picker.prioritizesVideoDevices = false
|
||||
picker.backgroundColor = .clear
|
||||
// Keep the native picker interactive without its route-dependent icon styling.
|
||||
picker.layer.opacity = 0
|
||||
addSubview(picker)
|
||||
icon.contentMode = .center
|
||||
icon.isUserInteractionEnabled = false
|
||||
icon.isAccessibilityElement = false
|
||||
addSubview(icon)
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
picker.frame = bounds
|
||||
icon.frame = bounds
|
||||
}
|
||||
}
|
||||
@@ -122,11 +122,7 @@ export async function GET(
|
||||
}))!
|
||||
|
||||
const quality = request.nextUrl.searchParams.get("quality") as
|
||||
| "low"
|
||||
| "medium"
|
||||
| "high"
|
||||
| "lossless"
|
||||
| null
|
||||
"low" | "medium" | "high" | "lossless" | null
|
||||
|
||||
const preferAtmos =
|
||||
request.nextUrl.searchParams.get("preferAtmos") === "true"
|
||||
@@ -157,7 +153,11 @@ export async function GET(
|
||||
const metadata = await music.parseFile(song.files[originalCodec])
|
||||
|
||||
if (!transcodeNeeded && originalCodec === "lossless") {
|
||||
if (browser.name === "Safari" && metadata.format.codec === "ALAC") {
|
||||
// Native iOS playback does not identify itself as Safari.
|
||||
const acceptsAlac =
|
||||
browser.name === "Safari" ||
|
||||
request.nextUrl.searchParams.get("losslessFormat") === "alac"
|
||||
if (acceptsAlac && metadata.format.codec === "ALAC") {
|
||||
try {
|
||||
return await streamFileResponse(
|
||||
request,
|
||||
|
||||
Reference in new issue
Block a user