Compare commits
No files matched your search
@@ -1,31 +1,50 @@
|
||||
import type { ConfigContext, ExpoConfig } from "expo/config"
|
||||
|
||||
export default ({ config }: ConfigContext): ExpoConfig => {
|
||||
const variant = process.env.APP_VARIANT ?? "production"
|
||||
if (!["development", "preview", "production"].includes(variant)) {
|
||||
const variant =
|
||||
process.env.APP_VARIANT ?? process.env.EAS_BUILD_PROFILE ?? "production"
|
||||
if (
|
||||
variant !== "development" &&
|
||||
variant !== "preview" &&
|
||||
variant !== "production"
|
||||
) {
|
||||
throw new Error(`Unsupported APP_VARIANT: ${variant}`)
|
||||
}
|
||||
|
||||
const suffix = variant === "production" ? "" : `.${variant}`
|
||||
const iconSuffix = variant === "production" ? "" : `-${variant}`
|
||||
const nameSuffix =
|
||||
variant === "development"
|
||||
? " (Development)"
|
||||
: variant === "preview"
|
||||
? " (Preview)"
|
||||
: ""
|
||||
const composer = {
|
||||
development: "oTunes Dev",
|
||||
preview: "oTunes Preview",
|
||||
production: "oTunes",
|
||||
}[variant]
|
||||
|
||||
return {
|
||||
...config,
|
||||
name: `${config.name}${nameSuffix}`,
|
||||
slug: config.slug!,
|
||||
scheme: variant === "production" ? "otunes" : `otunes-${variant}`,
|
||||
icon: `./assets/icon${iconSuffix}.png`,
|
||||
ios: {
|
||||
...config.ios,
|
||||
bundleIdentifier: `${config.ios!.bundleIdentifier}${suffix}`,
|
||||
icon: `./assets/${composer}.icon`,
|
||||
},
|
||||
android: {
|
||||
...config.android,
|
||||
package: `${config.android!.package}${suffix}`,
|
||||
icon: `./assets/android-icon${iconSuffix}.png`,
|
||||
adaptiveIcon: {
|
||||
monochromeImage: "./assets/android-icon-monochrome.png",
|
||||
foregroundImage: `./assets/android-icon-foreground${iconSuffix}.png`,
|
||||
backgroundImage: `./assets/android-icon-background${iconSuffix}.png`,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,11 @@
|
||||
"adaptiveIcon": {
|
||||
"monochromeImage": "./assets/android-icon-monochrome.png",
|
||||
"foregroundImage": "./assets/android-icon-foreground.png",
|
||||
"backgroundColor": "#C60322"
|
||||
"backgroundImage": "./assets/android-icon-background.png"
|
||||
},
|
||||
"userInterfaceStyle": "dark",
|
||||
"softwareKeyboardLayoutMode": "resize"
|
||||
"softwareKeyboardLayoutMode": "resize",
|
||||
"icon": "./assets/android-icon.png"
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router",
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
collectionInset,
|
||||
DiscHeader,
|
||||
} from "@/components/collection-list"
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
|
||||
import {
|
||||
@@ -75,6 +76,20 @@ export default function AlbumScreen() {
|
||||
[album]
|
||||
)
|
||||
|
||||
// Older servers do not include album format availability yet.
|
||||
const formatTracks = useCachedQuery(
|
||||
api.library.getSongsForPlayback,
|
||||
album && (album.hasLossless === undefined || album.hasAtmos === undefined)
|
||||
? { ids: songIds }
|
||||
: "skip"
|
||||
)
|
||||
const hasLossless =
|
||||
album?.hasLossless ??
|
||||
formatTracks?.some((track) => track && "lossless" in track.files)
|
||||
const hasAtmos =
|
||||
album?.hasAtmos ??
|
||||
formatTracks?.some((track) => track && "atmos" in track.files)
|
||||
|
||||
useEffect(() => {
|
||||
if (album) {
|
||||
rememberSongs(albumDetailSongs(album))
|
||||
@@ -183,7 +198,7 @@ export default function AlbumScreen() {
|
||||
<Ionicons
|
||||
name="ellipsis-horizontal"
|
||||
size={22}
|
||||
color={palette.foreground}
|
||||
color={palette.isDark ? "#fff" : "#000"}
|
||||
/>
|
||||
</Pressable>
|
||||
</MediaActionMenu>
|
||||
@@ -218,11 +233,49 @@ export default function AlbumScreen() {
|
||||
{album.artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexWrap: "wrap",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
{hasLossless ? (
|
||||
<>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
·
|
||||
</Text>
|
||||
) : null}
|
||||
<AudioFormatBadge
|
||||
format="lossless"
|
||||
color={palette.secondaryForeground}
|
||||
backgroundColor={palette.background}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{hasAtmos ? (
|
||||
<>
|
||||
{metadata || hasLossless ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
·
|
||||
</Text>
|
||||
) : null}
|
||||
<AudioFormatBadge
|
||||
format="atmos"
|
||||
color={palette.secondaryForeground}
|
||||
backgroundColor={palette.background}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</View>
|
||||
<View style={styles.actions}>
|
||||
<Pressable
|
||||
onPress={() => void toggleAlbumFavorite(album.id)}
|
||||
|
||||
@@ -39,10 +39,7 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
useCachedPaginatedQuery,
|
||||
useCachedQuery,
|
||||
} from "@/hooks/use-cached-query"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -55,7 +52,6 @@ import { showError } from "@/lib/toast"
|
||||
import { playlistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
const PLAYLIST_LABEL = "Add to Another Playlist"
|
||||
const OWNER_MENU_ACTIONS: MediaAction[] = [
|
||||
"share",
|
||||
@@ -74,27 +70,9 @@ export default function PlaylistScreen() {
|
||||
const playlistId = typeof id === "string" ? (id as Id<"playlists">) : null
|
||||
const playlist = useCachedQuery(
|
||||
api.playlists.browsePlaylistDetail,
|
||||
playlistId
|
||||
? {
|
||||
id: playlistId,
|
||||
includeSongs: false,
|
||||
}
|
||||
: "skip"
|
||||
)
|
||||
const {
|
||||
results: songs,
|
||||
status,
|
||||
loadMore,
|
||||
isCached,
|
||||
} = useCachedPaginatedQuery(
|
||||
api.playlists.browsePlaylistSongsPaginated,
|
||||
playlistId ? { id: playlistId } : "skip",
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
const allSongIds = useCachedQuery(
|
||||
api.playlists.getPlaylistSongIds,
|
||||
playlistId ? { playlistId } : "skip"
|
||||
playlistId ? { id: playlistId } : "skip"
|
||||
)
|
||||
const songs = playlist?.songs
|
||||
const coverUri =
|
||||
config && playlistId
|
||||
? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId)
|
||||
@@ -106,15 +84,10 @@ export default function PlaylistScreen() {
|
||||
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
|
||||
|
||||
useEffect(() => {
|
||||
rememberSongs(songs)
|
||||
if (songs) rememberSongs(songs)
|
||||
}, [songs])
|
||||
|
||||
if (
|
||||
playlist === undefined ||
|
||||
(status === "LoadingFirstPage" && !isCached) ||
|
||||
!config ||
|
||||
!settled
|
||||
) {
|
||||
if (playlist === undefined || !config || !settled) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
@@ -150,13 +123,9 @@ export default function PlaylistScreen() {
|
||||
<PlaylistContent
|
||||
onLayout={onLayout}
|
||||
playlist={playlist}
|
||||
songs={songs}
|
||||
allSongIds={allSongIds}
|
||||
songs={playlist.songs}
|
||||
coverUri={coverUri}
|
||||
palette={palette}
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -165,18 +134,14 @@ function PlaylistContent({
|
||||
onLayout,
|
||||
playlist,
|
||||
songs,
|
||||
allSongIds,
|
||||
coverUri,
|
||||
palette,
|
||||
onEndReached,
|
||||
}: {
|
||||
onLayout?: () => void
|
||||
playlist: BrowsePlaylistDetail
|
||||
songs: BrowseSong[]
|
||||
allSongIds: Id<"songs">[] | undefined
|
||||
coverUri: string
|
||||
palette: CoverPalette
|
||||
onEndReached: () => void
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const isFocused = useIsFocused()
|
||||
@@ -192,8 +157,7 @@ function PlaylistContent({
|
||||
const playlistId = playlist.id
|
||||
const isSubscribed = playlist.isSubscribed
|
||||
const canEdit = playlist.isOwner && playlistId !== null
|
||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const songIds = allSongIds ?? loadedSongIds
|
||||
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const swipeGroup = useSwipeRowGroup()
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
@@ -226,12 +190,12 @@ function PlaylistContent({
|
||||
)
|
||||
|
||||
const handlePlay = useCallback(() => {
|
||||
if (playlistId) void playPlaylist(playlistId, allSongIds)
|
||||
}, [allSongIds, playPlaylist, playlistId])
|
||||
if (playlistId) void playPlaylist(playlistId, songIds)
|
||||
}, [playPlaylist, playlistId, songIds])
|
||||
|
||||
const handleShuffle = useCallback(() => {
|
||||
if (playlistId) void playPlaylistShuffled(playlistId, allSongIds)
|
||||
}, [allSongIds, playPlaylistShuffled, playlistId])
|
||||
if (playlistId) void playPlaylistShuffled(playlistId, songIds)
|
||||
}, [playPlaylistShuffled, playlistId, songIds])
|
||||
|
||||
const handleSubscribeToggle = useCallback(async () => {
|
||||
if (!playlistId) return
|
||||
@@ -297,7 +261,7 @@ function PlaylistContent({
|
||||
<Ionicons
|
||||
name="ellipsis-horizontal"
|
||||
size={22}
|
||||
color={palette.foreground}
|
||||
color={palette.isDark ? "#fff" : "#000"}
|
||||
/>
|
||||
</Pressable>
|
||||
</MediaActionMenu>
|
||||
@@ -355,8 +319,6 @@ function PlaylistContent({
|
||||
indicatorStyle={palette.isDark ? "white" : "black"}
|
||||
contentContainerStyle={styles.listContent}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||
ListHeaderComponent={
|
||||
<PlaylistHero
|
||||
|
||||
@@ -15,10 +15,7 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
useCachedPaginatedQuery,
|
||||
useCachedQuery,
|
||||
} from "@/hooks/use-cached-query"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
@@ -29,32 +26,21 @@ import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
const SCREEN_OPTIONS = { title: "", headerLargeTitle: false }
|
||||
|
||||
export default function FavoritesScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const favorites = useCachedQuery(api.favorites.browseFavoritesSummary)
|
||||
const {
|
||||
results: songs,
|
||||
status,
|
||||
loadMore,
|
||||
isCached,
|
||||
} = useCachedPaginatedQuery(
|
||||
api.favorites.browseFavoritesSongsPaginated,
|
||||
{},
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
const favorites = useCachedQuery(api.favorites.browseFavoritesPlaylistDetail)
|
||||
const songs = favorites?.songs ?? []
|
||||
const { playInOrder, playShuffled, playFromSong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const songIds = favorites?.songIds ?? loadedSongIds
|
||||
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
|
||||
useEffect(() => {
|
||||
rememberSongs(songs)
|
||||
}, [songs])
|
||||
if (favorites) rememberSongs(favorites.songs)
|
||||
}, [favorites])
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
||||
@@ -88,11 +74,7 @@ export default function FavoritesScreen() {
|
||||
[handlePlaySong, handleSongMenuAction, isSongFavorite]
|
||||
)
|
||||
|
||||
if (
|
||||
favorites === undefined ||
|
||||
(status === "LoadingFirstPage" && !isCached) ||
|
||||
!config
|
||||
) {
|
||||
if (favorites === undefined || !config) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={SCREEN_OPTIONS} />
|
||||
@@ -125,10 +107,6 @@ export default function FavoritesScreen() {
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={styles.listContent}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
onEndReachedThreshold={0.5}
|
||||
ListHeaderComponent={
|
||||
<FavoritesHero
|
||||
title={favorites.title}
|
||||
|
||||
@@ -382,7 +382,7 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
: "This device does not support Dolby Atmos playback."
|
||||
}
|
||||
disabled={!dolbyAtmosSupported}
|
||||
value={user.preferAtmos ?? false}
|
||||
value={dolbyAtmosSupported && (user.preferAtmos ?? false)}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
|
||||
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 324 KiB |
|
After Width: | Height: | Size: 310 KiB |
|
After Width: | Height: | Size: 286 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 284 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 324 KiB |
|
Before Width: | Height: | Size: 963 KiB After Width: | Height: | Size: 284 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"fill" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.00000,0.55106,0.91748,1.00000",
|
||||
"display-p3:0.00320,0.24546,0.91602,1.00000"
|
||||
]
|
||||
},
|
||||
"groups" : [
|
||||
{
|
||||
"layers" : [
|
||||
{
|
||||
"fill-specializations" : [
|
||||
{
|
||||
"value" : "automatic"
|
||||
},
|
||||
{
|
||||
"appearance" : "dark",
|
||||
"value" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.00000,0.55106,0.91748,1.00000",
|
||||
"display-p3:0.00320,0.24546,0.91602,1.00000"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1.5,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"shadow" : {
|
||||
"kind" : "neutral",
|
||||
"opacity" : 0.6
|
||||
},
|
||||
"translucency" : {
|
||||
"enabled" : false,
|
||||
"value" : 0.2
|
||||
}
|
||||
}
|
||||
],
|
||||
"supported-platforms" : {
|
||||
"circles" : [
|
||||
"watchOS"
|
||||
],
|
||||
"squares" : "shared"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 8.8 KiB |
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"fill" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.03297,0.65562,0.91748,1.00000",
|
||||
"display-p3:0.01787,0.85470,0.91602,1.00000"
|
||||
]
|
||||
},
|
||||
"groups" : [
|
||||
{
|
||||
"layers" : [
|
||||
{
|
||||
"fill-specializations" : [
|
||||
{
|
||||
"value" : "automatic"
|
||||
},
|
||||
{
|
||||
"appearance" : "dark",
|
||||
"value" : {
|
||||
"linear-gradient" : [
|
||||
"display-p3:0.03297,0.65562,0.91748,1.00000",
|
||||
"display-p3:0.01787,0.85470,0.91602,1.00000"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1.5,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"shadow" : {
|
||||
"kind" : "neutral",
|
||||
"opacity" : 0.6
|
||||
},
|
||||
"translucency" : {
|
||||
"enabled" : false,
|
||||
"value" : 0.2
|
||||
}
|
||||
}
|
||||
],
|
||||
"supported-platforms" : {
|
||||
"circles" : [
|
||||
"watchOS"
|
||||
],
|
||||
"squares" : "shared"
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
"image-name" : "music.note.png",
|
||||
"name" : "music.note",
|
||||
"position" : {
|
||||
"scale" : 1,
|
||||
"scale" : 1.5,
|
||||
"translation-in-points" : [
|
||||
0,
|
||||
0
|
||||
|
||||
@@ -2,6 +2,7 @@ import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import {
|
||||
createAudioPlaylist,
|
||||
setAudioModeAsync,
|
||||
setIsAudioActiveAsync,
|
||||
type AudioMetadata,
|
||||
type AudioPlaylist,
|
||||
type AudioPlaylistStatus,
|
||||
@@ -774,6 +775,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
playlist.play()
|
||||
} else {
|
||||
playlist.pause()
|
||||
// Enable audio for the restored queue without starting playback.
|
||||
try {
|
||||
await setIsAudioActiveAsync(true)
|
||||
} catch {
|
||||
if (isCurrentLoad()) {
|
||||
showError("Audio playback could not be initialized.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
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()
|
||||
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
|
||||
export const dolbyAtmosSupported = Platform.OS === "ios"
|
||||
@@ -1,3 +1,4 @@
|
||||
import { dolbyAtmosSupported } from "@/lib/playback-capabilities"
|
||||
import { Platform } from "react-native"
|
||||
import type { AudioSource } from "expo-audio"
|
||||
|
||||
@@ -53,7 +54,7 @@ export function songPlayUrl(
|
||||
const params = new URLSearchParams()
|
||||
if (Platform.OS === "ios") params.set("losslessFormat", "alac")
|
||||
if (quality) params.set("quality", quality)
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
if (dolbyAtmosSupported && preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play${query ? `?${query}` : ""}`
|
||||
}
|
||||
@@ -66,7 +67,7 @@ export function songHlsPlaylistUrl(
|
||||
) {
|
||||
const params = new URLSearchParams()
|
||||
if (quality) params.set("quality", quality)
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
if (dolbyAtmosSupported && preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play/hls${query ? `?${query}` : ""}`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package expo.modules.audiooutput
|
||||
|
||||
import android.media.MediaCodecList
|
||||
import android.os.Build
|
||||
import androidx.mediarouter.app.SystemOutputSwitcherDialogController
|
||||
import expo.modules.kotlin.functions.Queues
|
||||
@@ -11,16 +10,6 @@ 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) {
|
||||
|
||||
@@ -26,8 +26,9 @@ final class AudioOutputView: ExpoView {
|
||||
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
|
||||
// Hide only the native glyph. Making the picker transparent prevents taps.
|
||||
picker.tintColor = .clear
|
||||
picker.activeTintColor = .clear
|
||||
addSubview(picker)
|
||||
icon.contentMode = .center
|
||||
icon.isUserInteractionEnabled = false
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
|
||||
import Link from "next/link"
|
||||
import { Home, Search } from "lucide-react"
|
||||
|
||||
@@ -8,6 +10,7 @@ import { Button } from "@/components/ui/button"
|
||||
export default function Page() {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<div className="flex flex-1 items-center justify-center px-6 pb-28">
|
||||
<div className="flex max-w-md flex-col items-center text-center">
|
||||
<p className="text-sm font-medium text-muted-foreground">404</p>
|
||||
|
||||
@@ -5,6 +5,8 @@ import { PlayerBar } from "@/components/player-bar"
|
||||
import { LazyQueuePanel } from "@/components/lazy-queue-panel"
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
||||
import { AppSidebar } from "@/components/app-sidebar"
|
||||
import { ScrollRestoration } from "@/components/scroll-restoration"
|
||||
import { Suspense } from "react"
|
||||
|
||||
export default function AppLayout({
|
||||
children,
|
||||
@@ -18,7 +20,11 @@ export default function AppLayout({
|
||||
<FavoritesProvider>
|
||||
<AppSidebar />
|
||||
<div className="flex min-h-svh min-w-0 flex-1">
|
||||
<SidebarInset className="min-w-0 flex-1">{children}</SidebarInset>
|
||||
<SidebarInset className="min-w-0 flex-1">
|
||||
<Suspense>
|
||||
<ScrollRestoration>{children}</ScrollRestoration>
|
||||
</Suspense>
|
||||
</SidebarInset>
|
||||
<LazyQueuePanel />
|
||||
</div>
|
||||
<PlayerBar />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { Plus } from "lucide-react"
|
||||
|
||||
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
||||
@@ -17,7 +18,10 @@ export default function Page() {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Playlists</h1>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="text-lg font-semibold">Playlists</h1>
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { SearchResultsSkeleton } from "@/components/library-skeletons"
|
||||
import { SearchPrompt } from "@/components/search-prompt"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
@@ -11,7 +12,8 @@ export default function Loading() {
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-center border-b px-4 py-3">
|
||||
<header className="flex items-center justify-center gap-2 border-b px-4 py-3">
|
||||
<MobileSidebarTrigger />
|
||||
<Skeleton className="h-10 w-full max-w-xl rounded-full" />
|
||||
</header>
|
||||
{hasQuery ? <SearchResultsSkeleton /> : <SearchPrompt />}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { Suspense, useCallback, useEffect, useRef, useState } from "react"
|
||||
import { SearchIcon } from "lucide-react"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
@@ -212,7 +213,8 @@ function SearchPageContent() {
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-center border-b px-4 py-3">
|
||||
<header className="flex items-center justify-center gap-2 border-b px-4 py-3">
|
||||
<MobileSidebarTrigger />
|
||||
<div className="relative w-full max-w-xl">
|
||||
<SearchIcon className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { audioContentTypeForPath } from "@/lib/audio-content-type"
|
||||
import { seekableLosslessFile } from "@/lib/server-lossless"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { ffmpegToReadableStream, streamFile } from "@/lib/server-audio-stream"
|
||||
import { NextRequest, NextResponse, userAgent } from "next/server"
|
||||
@@ -169,26 +170,9 @@ export async function GET(
|
||||
}
|
||||
}
|
||||
|
||||
const ffmpegArgs = [
|
||||
"-nostdin",
|
||||
"-i",
|
||||
song.files[originalCodec],
|
||||
"-f",
|
||||
"flac",
|
||||
"pipe:1",
|
||||
]
|
||||
|
||||
try {
|
||||
const ffmpegProcess = spawn("ffmpeg", ffmpegArgs)
|
||||
const stream = ffmpegToReadableStream(ffmpegProcess)
|
||||
|
||||
return new NextResponse(stream, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "audio/flac",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
})
|
||||
const file = await seekableLosslessFile(song.files[originalCodec])
|
||||
return await streamFileResponse(request, file, "audio/flac")
|
||||
} catch {
|
||||
return new Response("Server Error", { status: 500 })
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 8.6 KiB |
@@ -1,10 +1,12 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { Play, Share2, Shuffle, Star } from "lucide-react"
|
||||
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { MediaCollectionFooter } from "@/components/media-collection-footer"
|
||||
import { TrackNumberPlayButton } from "@/components/track-number-play-button"
|
||||
|
||||
@@ -20,6 +22,8 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { cn } from "@/lib/utils"
|
||||
@@ -272,6 +276,20 @@ export function AlbumView({
|
||||
[album.tracks]
|
||||
)
|
||||
|
||||
// Older servers do not include album format availability yet.
|
||||
const formatTracks = useCachedQuery(
|
||||
api.library.getSongsForPlayback,
|
||||
album.hasLossless === undefined || album.hasAtmos === undefined
|
||||
? { ids: albumSongIds }
|
||||
: "skip"
|
||||
)
|
||||
const hasLossless =
|
||||
album.hasLossless ??
|
||||
formatTracks?.some((track) => track && "lossless" in track.files)
|
||||
const hasAtmos =
|
||||
album.hasAtmos ??
|
||||
formatTracks?.some((track) => track && "atmos" in track.files)
|
||||
|
||||
React.useEffect(() => {
|
||||
rememberSongs(albumDetailSongs(album))
|
||||
}, [album])
|
||||
@@ -371,7 +389,8 @@ export function AlbumView({
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<PageHeader />
|
||||
<ScrollArea className="min-h-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:block!">
|
||||
<div className="pb-28">
|
||||
<div className="mx-auto w-full min-w-0 max-w-9/10">
|
||||
<div className="flex flex-col gap-8 pt-6 pb-8 sm:flex-row sm:items-end">
|
||||
@@ -400,9 +419,23 @@ export function AlbumView({
|
||||
>
|
||||
{album.artist.name}
|
||||
</Link>
|
||||
{metadata ? (
|
||||
<p className="text-sm text-muted-foreground">{metadata}</p>
|
||||
) : null}
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground sm:justify-start">
|
||||
{metadata ? <span>{metadata}</span> : null}
|
||||
{hasLossless ? (
|
||||
<>
|
||||
{metadata ? <span aria-hidden>·</span> : null}
|
||||
<AudioFormatBadge format="lossless" />
|
||||
</>
|
||||
) : null}
|
||||
{hasAtmos ? (
|
||||
<>
|
||||
{metadata || hasLossless ? (
|
||||
<span aria-hidden>·</span>
|
||||
) : null}
|
||||
<AudioFormatBadge format="atmos" />
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
useSidebar,
|
||||
} from "@/components/ui/sidebar"
|
||||
import { ThemeToggle } from "@/components/theme-toggle"
|
||||
import Image from "next/image"
|
||||
@@ -63,6 +64,7 @@ const library = [
|
||||
]
|
||||
|
||||
export function AppSidebar() {
|
||||
const { setOpenMobile } = useSidebar()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
const { signOut } = useAuthActions()
|
||||
@@ -120,7 +122,7 @@ export function AppSidebar() {
|
||||
{browse.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton isActive={pathname === item.path} asChild>
|
||||
<Link href={item.path}>
|
||||
<Link href={item.path} onClick={() => setOpenMobile(false)}>
|
||||
<item.icon />
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
@@ -144,7 +146,7 @@ export function AppSidebar() {
|
||||
}
|
||||
asChild
|
||||
>
|
||||
<Link href={item.path}>
|
||||
<Link href={item.path} onClick={() => setOpenMobile(false)}>
|
||||
<item.icon />
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
@@ -162,7 +164,7 @@ export function AppSidebar() {
|
||||
{playlistNav.map((item) => (
|
||||
<SidebarMenuItem key={item.path}>
|
||||
<SidebarMenuButton isActive={pathname === item.path} asChild>
|
||||
<Link href={item.path}>
|
||||
<Link href={item.path} onClick={() => setOpenMobile(false)}>
|
||||
<item.icon />
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import { Play, Shuffle } from "lucide-react"
|
||||
@@ -64,6 +65,7 @@ export function ArtistView({
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import type { PlaybackFormat } from "@otunes/convex/playback-stream"
|
||||
|
||||
const MARK_HEIGHT = 11
|
||||
|
||||
function DolbyMark({ color }: { color: string }) {
|
||||
return (
|
||||
<svg
|
||||
width={(MARK_HEIGHT * 23) / 16}
|
||||
height={MARK_HEIGHT}
|
||||
viewBox="0 0 23 16"
|
||||
>
|
||||
<path d="M0 0H2.5A8 8 0 0 1 2.5 16H0Z" fill={color} />
|
||||
<path d="M23 0H20.5A8 8 0 0 0 20.5 16H23Z" fill={color} />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
const LOSSLESS_PEAKS = [110, 215, 320]
|
||||
const LOSSLESS_THIN_WIDTH = 24
|
||||
const LOSSLESS_STROKES: [peak: number, d: string][] = [
|
||||
[110, "M-70 320C-62 245 -38 166 0 166"],
|
||||
[215, "M-70 320C-62 245 -38 166 0 166"],
|
||||
[320, "M-30 185C-22 173 -11 166 0 166"],
|
||||
[110, "M166 413C176 413 186 406 194 395"],
|
||||
[215, "M166 413C200 413 226 340 240 275"],
|
||||
[320, "M166 413C200 413 226 340 240 275"],
|
||||
]
|
||||
const LOSSLESS_FALL =
|
||||
"M0 178L4 179L8 181L12 184L16 189L20 196L23 204L27 213L30 223L34 233L39 243L43 254L48 266L53 278L58 289L62 301L66 313L71 325L75 336L79 347L83 357L86 364L89 370L93 377L97 382L101 387L105 392L109 397L113 401L117 405L121 408L126 412L130 415L134 417L139 419L143 421L148 423L152 424L157 424L161 425L166 425L166 401L163 401L161 400L159 400L157 399L154 397L152 396L151 394L149 392L147 389L145 386L143 383L142 380L140 376L138 371L137 367L135 362L134 357L132 351L130 345L127 339L124 330L120 319L116 308L111 297L107 285L102 272L98 260L93 248L88 235L82 223L76 212L69 201L61 192L53 183L45 175L37 168L28 163L19 158L10 155L0 154Z"
|
||||
const LOSSLESS_FALL_GAP =
|
||||
"M0 178L4 180L6 184L8 190L9 197L11 203L14 210L17 219L21 228L24 238L29 248L33 259L38 270L43 282L47 293L52 305L56 317L60 328L64 340L68 351L73 361L76 368L79 375L83 381L87 387L91 393L95 398L100 403L104 408L109 412L113 416L118 419L124 422L130 424L135 425L141 426L147 426L152 426L157 425L161 425L166 425L166 401L163 401L161 399L159 398L158 395L157 393L156 390L155 387L155 384L154 381L153 379L152 376L150 373L149 369L148 366L146 361L145 357L143 352L142 347L140 341L137 335L134 326L130 315L126 304L122 293L117 281L113 268L108 256L103 243L98 231L92 219L86 207L79 196L71 186L62 177L53 168L44 161L32 157L21 155L10 154L0 154Z"
|
||||
|
||||
/**
|
||||
* Three overlapping waves. Each thick downstroke is outlined in the
|
||||
* background color so it reads as passing over the strokes behind it.
|
||||
*/
|
||||
function LosslessMark({
|
||||
color,
|
||||
backgroundColor,
|
||||
}: {
|
||||
color: string
|
||||
backgroundColor: string
|
||||
}) {
|
||||
return (
|
||||
<svg
|
||||
width={(MARK_HEIGHT * 544) / 271}
|
||||
height={MARK_HEIGHT}
|
||||
viewBox="28 154 544 271"
|
||||
>
|
||||
{LOSSLESS_STROKES.map(([peak, d], index) => (
|
||||
<path
|
||||
key={index}
|
||||
d={d}
|
||||
transform={`translate(${peak})`}
|
||||
stroke={color}
|
||||
strokeWidth={LOSSLESS_THIN_WIDTH}
|
||||
strokeLinecap="round"
|
||||
fill="none"
|
||||
/>
|
||||
))}
|
||||
{LOSSLESS_PEAKS.map((peak) => (
|
||||
<g key={peak} transform={`translate(${peak})`}>
|
||||
<path d={LOSSLESS_FALL_GAP} fill={backgroundColor} />
|
||||
<path d={LOSSLESS_FALL} fill={color} />
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
export function AudioFormatBadge({
|
||||
format,
|
||||
iconOnly = false,
|
||||
backgroundColor = "var(--background)",
|
||||
}: {
|
||||
format: PlaybackFormat
|
||||
iconOnly?: boolean
|
||||
backgroundColor?: string
|
||||
}) {
|
||||
const label = format === "atmos" ? "Dolby Atmos" : "Lossless"
|
||||
return (
|
||||
<span
|
||||
className="inline-flex shrink-0 items-center gap-[3px] text-[13px] font-medium"
|
||||
title={iconOnly ? label : undefined}
|
||||
>
|
||||
<span aria-hidden="true">
|
||||
{format === "atmos" ? (
|
||||
<DolbyMark color="currentColor" />
|
||||
) : (
|
||||
<LosslessMark
|
||||
color="currentColor"
|
||||
backgroundColor={backgroundColor}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className={iconOnly ? "sr-only" : undefined}>{label}</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { albumGridClassName } from "@/lib/album-grid-classes"
|
||||
import { TRACK_LIST_CONTAINER } from "@/lib/selection-range-styles"
|
||||
@@ -18,10 +19,16 @@ function LoadingRegion({
|
||||
)
|
||||
}
|
||||
|
||||
export function PageHeader({ title }: { title: string }) {
|
||||
export function PageHeader({ title }: { title?: string }) {
|
||||
return (
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">{title}</h1>
|
||||
<header
|
||||
className={cn(
|
||||
"flex shrink-0 items-center gap-2 border-b px-4 py-3",
|
||||
!title && "md:hidden"
|
||||
)}
|
||||
>
|
||||
<MobileSidebarTrigger />
|
||||
{title ? <h1 className="text-lg font-semibold">{title}</h1> : null}
|
||||
</header>
|
||||
)
|
||||
}
|
||||
@@ -133,6 +140,7 @@ export function SongListSkeleton() {
|
||||
export function CollectionDetailSkeleton() {
|
||||
return (
|
||||
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
||||
<PageHeader />
|
||||
<div className="mx-auto w-full max-w-9/10 min-w-0">
|
||||
<div className="flex flex-col gap-8 px-6 pt-6 pb-8 sm:flex-row sm:items-end">
|
||||
<Skeleton className="mx-auto aspect-square w-full max-w-60 shrink-0 rounded-lg sm:mx-0" />
|
||||
@@ -161,6 +169,7 @@ export function CollectionDetailSkeleton() {
|
||||
export function ArtistDetailSkeleton() {
|
||||
return (
|
||||
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
||||
<PageHeader />
|
||||
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
||||
<Skeleton className="size-32 shrink-0 rounded-full sm:size-40" />
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use client"
|
||||
|
||||
import { Menu } from "lucide-react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { useSidebar } from "@/components/ui/sidebar"
|
||||
|
||||
export function MobileSidebarTrigger() {
|
||||
const { openMobile, setOpenMobile } = useSidebar()
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-11 shrink-0 md:hidden"
|
||||
aria-label="Open sidebar"
|
||||
aria-expanded={openMobile}
|
||||
onClick={() => setOpenMobile(true)}
|
||||
>
|
||||
<Menu />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
|
||||
export function PageMessage({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<div className="flex flex-1 items-center justify-center pb-28">
|
||||
<p className="text-sm text-muted-foreground">{children}</p>
|
||||
</div>
|
||||
|
||||
@@ -19,7 +19,11 @@ import { toast } from "sonner"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { playbackStreamPlan } from "@otunes/convex/playback-stream"
|
||||
import {
|
||||
playbackFormat,
|
||||
type PlaybackFormat,
|
||||
playbackStreamPlan,
|
||||
} from "@otunes/convex/playback-stream"
|
||||
import {
|
||||
ANONYMOUS_CACHE_SCOPE,
|
||||
useCacheScope,
|
||||
@@ -44,6 +48,7 @@ const PROGRESS_SAVE_INTERVAL_MS = 5000
|
||||
type PlaybackContextValue = {
|
||||
queueSongIds: Id<"songs">[]
|
||||
queueHistorySongIds: Id<"songs">[]
|
||||
currentFormat: PlaybackFormat | null
|
||||
currentSong: BrowseSong | null
|
||||
shuffleEnabled: boolean
|
||||
repeatEnabled: RepeatMode
|
||||
@@ -1321,11 +1326,21 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
skipPrevious,
|
||||
})
|
||||
|
||||
const currentFormat =
|
||||
currentSongDoc && user
|
||||
? playbackFormat(
|
||||
currentSongDoc.files,
|
||||
user.playbackQuality,
|
||||
dolbyAtmosSupported === true && (user.preferAtmos ?? false)
|
||||
)
|
||||
: null
|
||||
|
||||
const value = useMemo<PlaybackContextValue>(
|
||||
() => ({
|
||||
queueSongIds: playback.queue,
|
||||
queueHistorySongIds: playback.history,
|
||||
currentSong,
|
||||
currentFormat,
|
||||
shuffleEnabled: playback.shuffleEnabled,
|
||||
repeatEnabled: playback.repeatEnabled,
|
||||
queueOpen,
|
||||
@@ -1359,6 +1374,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
[
|
||||
playback,
|
||||
currentSong,
|
||||
currentFormat,
|
||||
queueOpen,
|
||||
isPlaybackActive,
|
||||
volume,
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import {
|
||||
ListMusic,
|
||||
Music,
|
||||
MessageSquareQuote,
|
||||
Pause,
|
||||
Play,
|
||||
Repeat,
|
||||
@@ -15,7 +16,12 @@ import {
|
||||
Volume2,
|
||||
} from "lucide-react"
|
||||
|
||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import {
|
||||
usePlayback,
|
||||
usePlaybackProgress,
|
||||
@@ -26,8 +32,6 @@ import { useSidebar } from "@/components/ui/sidebar"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const PLACEHOLDER_TIME = "--:--"
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const total = Math.max(0, Math.floor(seconds))
|
||||
const minutes = Math.floor(total / 60)
|
||||
@@ -38,6 +42,7 @@ function formatDuration(seconds: number): string {
|
||||
export function PlayerBar() {
|
||||
const {
|
||||
currentSong,
|
||||
currentFormat,
|
||||
shuffleEnabled,
|
||||
repeatEnabled,
|
||||
queueOpen,
|
||||
@@ -66,23 +71,25 @@ export function PlayerBar() {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
||||
sidebarExpanded ? "left-[16rem] right-0" : "inset-x-0",
|
||||
"@container pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
||||
sidebarExpanded ? "right-0 left-[16rem]" : "inset-x-0",
|
||||
queueOpen && !isMobile && "right-72"
|
||||
)}
|
||||
>
|
||||
<div className="pointer-events-auto flex w-full max-w-3xl flex-col gap-2 rounded-xl border bg-card/80 px-3 py-2 shadow-lg backdrop-blur">
|
||||
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
||||
<div className="flex items-center justify-start gap-1">
|
||||
<div className="pointer-events-auto flex w-full max-w-6xl items-center gap-2 rounded-full border border-white/20 bg-[#303033] px-3 py-2 text-white shadow-lg @min-[640px]:gap-5 @min-[640px]:px-5 @min-[640px]:py-3">
|
||||
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-1 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Shuffle"
|
||||
aria-pressed={shuffleEnabled}
|
||||
className={cn(shuffleEnabled && "text-primary")}
|
||||
className={cn(
|
||||
"hidden @min-[640px]:inline-flex",
|
||||
shuffleEnabled ? "text-white" : "text-white/40"
|
||||
)}
|
||||
onClick={() => void toggleShuffle()}
|
||||
>
|
||||
<Shuffle />
|
||||
<Shuffle className="size-4 @min-[640px]:size-6" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -91,7 +98,7 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => void skipPrevious()}
|
||||
>
|
||||
<SkipBack />
|
||||
<SkipBack className="size-4 fill-current @min-[640px]:size-6" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -100,7 +107,11 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
>
|
||||
{isPlaying ? <Pause /> : <Play className="fill-current" />}
|
||||
{isPlaying ? (
|
||||
<Pause className="size-5! fill-current @min-[640px]:size-8!" />
|
||||
) : (
|
||||
<Play className="size-5! fill-current @min-[640px]:size-8!" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -109,52 +120,113 @@ export function PlayerBar() {
|
||||
disabled={!hasQueue}
|
||||
onClick={() => void skipNext()}
|
||||
>
|
||||
<SkipForward />
|
||||
<SkipForward className="size-4 fill-current @min-[640px]:size-6" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Repeat"
|
||||
aria-pressed={repeatEnabled !== "none"}
|
||||
className={cn(repeatEnabled !== "none" && "text-primary")}
|
||||
className={cn(
|
||||
"hidden @min-[640px]:inline-flex",
|
||||
repeatEnabled !== "none" ? "text-white" : "text-white/40"
|
||||
)}
|
||||
onClick={() => void cycleRepeat()}
|
||||
>
|
||||
{repeatEnabled === "once" ? <Repeat1 /> : <Repeat />}
|
||||
{repeatEnabled === "once" ? (
|
||||
<Repeat1 className="size-4 @min-[640px]:size-6" />
|
||||
) : (
|
||||
<Repeat className="size-4 @min-[640px]:size-6" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex h-10 min-w-0 items-center justify-center gap-3 px-2">
|
||||
<div className="relative flex min-w-0 flex-1 items-center gap-2 pb-2 @min-[640px]:gap-3">
|
||||
{currentSong ? (
|
||||
<>
|
||||
<div className="relative size-8 shrink-0 overflow-hidden rounded">
|
||||
<div className="relative size-9 shrink-0 overflow-hidden rounded @min-[640px]:size-14">
|
||||
<Image
|
||||
src={albumCoverUrl(currentSong.album.id)}
|
||||
alt={currentSong.album.title}
|
||||
fill
|
||||
sizes="32px"
|
||||
sizes="56px"
|
||||
className="object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex h-10 min-w-0 max-w-48 flex-col justify-center overflow-hidden sm:max-w-64">
|
||||
<PlaybackSongMeta song={currentSong} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<Link
|
||||
href={`/album/${currentSong.album.id}`}
|
||||
className="block truncate text-sm font-semibold hover:underline @min-[640px]:text-xl"
|
||||
>
|
||||
{currentSong.title}
|
||||
</Link>
|
||||
<p className="truncate text-xs @min-[640px]:text-lg">
|
||||
<Link
|
||||
href={`/artist/${currentSong.artist.id}`}
|
||||
className="hover:underline"
|
||||
>
|
||||
{currentSong.artist.name}
|
||||
</Link>
|
||||
<span aria-hidden> · </span>
|
||||
<Link
|
||||
href={`/album/${currentSong.album.id}`}
|
||||
className="hover:underline"
|
||||
>
|
||||
{currentSong.album.title}
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
{currentFormat ? (
|
||||
<AudioFormatBadge
|
||||
format={currentFormat}
|
||||
iconOnly
|
||||
backgroundColor="#303033"
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<div className="flex size-8 shrink-0 items-center justify-center">
|
||||
<Image
|
||||
src="/logo-monochrome.svg"
|
||||
alt="oTunes"
|
||||
width={14}
|
||||
height={24}
|
||||
className="h-6 w-auto opacity-85"
|
||||
/>
|
||||
</div>
|
||||
<Image
|
||||
src="/logo-monochrome.svg"
|
||||
alt="oTunes"
|
||||
width={14}
|
||||
height={24}
|
||||
className="mx-auto my-2 h-6 w-auto opacity-85"
|
||||
/>
|
||||
)}
|
||||
<div className="absolute inset-x-0 -bottom-1">
|
||||
<Slider
|
||||
className={cn(
|
||||
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-white/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-white/30",
|
||||
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
|
||||
)}
|
||||
min={0}
|
||||
max={maxDuration}
|
||||
step={0.1}
|
||||
value={[displayTime]}
|
||||
disabled={!hasActiveSong}
|
||||
onValueChange={([value]) => {
|
||||
setIsSeeking(true)
|
||||
setSeekValue(value)
|
||||
}}
|
||||
onValueCommit={([value]) => {
|
||||
seekTo(value)
|
||||
setIsSeeking(false)
|
||||
}}
|
||||
aria-label="Seek"
|
||||
aria-valuetext={`${formatDuration(displayTime)} of ${formatDuration(duration)}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button variant="ghost" size="icon" aria-label="Lyrics" disabled>
|
||||
<Music />
|
||||
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-2 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="hidden @min-[640px]:inline-flex"
|
||||
aria-label="Lyrics"
|
||||
disabled
|
||||
>
|
||||
<MessageSquareQuote className="size-4 @min-[640px]:size-6" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -164,63 +236,24 @@ export function PlayerBar() {
|
||||
className={cn(queueOpen && "text-primary")}
|
||||
onClick={toggleQueueOpen}
|
||||
>
|
||||
<ListMusic />
|
||||
<ListMusic className="size-4 @min-[640px]:size-6" />
|
||||
</Button>
|
||||
<div className="hidden items-center gap-2 sm:flex">
|
||||
<Volume2 className="size-4 shrink-0 text-muted-foreground" />
|
||||
<Slider
|
||||
className="w-20"
|
||||
min={0}
|
||||
max={100}
|
||||
value={[volume]}
|
||||
onValueChange={([value]) => setVolume(value)}
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Volume"
|
||||
className="sm:hidden"
|
||||
>
|
||||
<Volume2 />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 px-1">
|
||||
<span
|
||||
className="w-9 shrink-0 text-right text-xs tabular-nums text-muted-foreground"
|
||||
aria-hidden
|
||||
>
|
||||
{hasActiveSong ? formatDuration(displayTime) : PLACEHOLDER_TIME}
|
||||
</span>
|
||||
<Slider
|
||||
className={cn(
|
||||
"flex-1",
|
||||
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
|
||||
)}
|
||||
min={0}
|
||||
max={maxDuration}
|
||||
step={0.1}
|
||||
value={[displayTime]}
|
||||
disabled={!hasActiveSong}
|
||||
onValueChange={([value]) => {
|
||||
setIsSeeking(true)
|
||||
setSeekValue(value)
|
||||
}}
|
||||
onValueCommit={([value]) => {
|
||||
seekTo(value)
|
||||
setIsSeeking(false)
|
||||
}}
|
||||
aria-label="Seek"
|
||||
/>
|
||||
<span
|
||||
className="w-9 shrink-0 text-xs tabular-nums text-muted-foreground"
|
||||
aria-hidden
|
||||
>
|
||||
{hasActiveSong ? formatDuration(duration) : PLACEHOLDER_TIME}
|
||||
</span>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="ghost" size="icon" aria-label="Volume">
|
||||
<Volume2 className="size-4 @min-[640px]:size-6" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent side="top" align="end" className="w-40">
|
||||
<Slider
|
||||
min={0}
|
||||
max={100}
|
||||
value={[volume]}
|
||||
onValueChange={([value]) => setVolume(value)}
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { PageHeader } from "@/components/library-skeletons"
|
||||
import { stationArtistId } from "@/lib/station-artist"
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
@@ -518,6 +519,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<PageHeader />
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="mx-auto w-full min-w-0 max-w-9/10">
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
"use client"
|
||||
|
||||
import { useLayoutEffect, useRef } from "react"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
|
||||
const historyKey = "otunesScrollKey"
|
||||
const scrollSelector = '[data-slot="scroll-area-viewport"], .overflow-y-auto'
|
||||
type Position = { top: number; left: number }
|
||||
|
||||
// Track page containers independently of the window, including split library views.
|
||||
export function ScrollRestoration({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
const route = `${pathname}?${searchParams.toString()}`
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const positions = useRef(new Map<string, Map<number, Position>>())
|
||||
useLayoutEffect(() => {
|
||||
const root = rootRef.current
|
||||
if (!root) return
|
||||
|
||||
const key =
|
||||
typeof history.state?.[historyKey] === "string"
|
||||
? (history.state[historyKey] as string)
|
||||
: crypto.randomUUID()
|
||||
history.replaceState({ ...history.state, [historyKey]: key }, "")
|
||||
const saved = positions.current.get(key)
|
||||
const pending = new Map(saved)
|
||||
if (!positions.current.has(key)) positions.current.set(key, new Map())
|
||||
// Bound memory during long listening sessions.
|
||||
if (positions.current.size > 100) {
|
||||
const oldest = positions.current.keys().next().value
|
||||
if (oldest !== undefined) positions.current.delete(oldest)
|
||||
}
|
||||
|
||||
const containers = () =>
|
||||
Array.from(root.querySelectorAll<HTMLElement>(scrollSelector)).filter(
|
||||
(element) => element.getClientRects().length > 0
|
||||
)
|
||||
const restore = () => {
|
||||
for (const [index, element] of containers().entries()) {
|
||||
const position = pending.get(index)
|
||||
if (!position) continue
|
||||
element.scrollTo({
|
||||
top: position.top,
|
||||
left: position.left,
|
||||
behavior: "instant",
|
||||
})
|
||||
// Keep waiting if asynchronous content is still too short.
|
||||
if (
|
||||
Math.abs(element.scrollTop - position.top) < 1 &&
|
||||
Math.abs(element.scrollLeft - position.left) < 1
|
||||
) {
|
||||
pending.delete(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
const record = (event: Event) => {
|
||||
if (!(event.target instanceof HTMLElement)) return
|
||||
const index = containers().indexOf(event.target)
|
||||
if (index < 0 || pending.has(index)) return
|
||||
positions.current.get(key)?.set(index, {
|
||||
top: event.target.scrollTop,
|
||||
left: event.target.scrollLeft,
|
||||
})
|
||||
}
|
||||
const stopRestoring = () => {
|
||||
pending.clear()
|
||||
observer.disconnect()
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
const observer = new MutationObserver(() => {
|
||||
restore()
|
||||
for (const element of containers()) {
|
||||
resizeObserver.observe(element)
|
||||
for (const child of element.children) resizeObserver.observe(child)
|
||||
}
|
||||
})
|
||||
const resizeObserver = new ResizeObserver(restore)
|
||||
if (pending.size) {
|
||||
observer.observe(root, { childList: true, subtree: true })
|
||||
for (const element of containers()) {
|
||||
resizeObserver.observe(element)
|
||||
for (const child of element.children) resizeObserver.observe(child)
|
||||
}
|
||||
restore()
|
||||
}
|
||||
const timeout = window.setTimeout(stopRestoring, 10_000)
|
||||
root.addEventListener("scroll", record, true)
|
||||
root.addEventListener("wheel", stopRestoring, { passive: true })
|
||||
root.addEventListener("touchstart", stopRestoring, { passive: true })
|
||||
root.addEventListener("keydown", stopRestoring)
|
||||
return () => {
|
||||
window.clearTimeout(timeout)
|
||||
stopRestoring()
|
||||
root.removeEventListener("scroll", record, true)
|
||||
root.removeEventListener("wheel", stopRestoring)
|
||||
root.removeEventListener("touchstart", stopRestoring)
|
||||
root.removeEventListener("keydown", stopRestoring)
|
||||
}
|
||||
}, [route])
|
||||
|
||||
return (
|
||||
<div ref={rootRef} className="contents">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
||||
import { stationArtistId } from "@/lib/station-artist"
|
||||
import { useEffect, useMemo, useState, useRef, MouseEvent } from "react"
|
||||
import Image from "next/image"
|
||||
@@ -362,7 +363,10 @@ export function SongsView() {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Songs</h1>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="text-lg font-semibold">Songs</h1>
|
||||
</div>
|
||||
</header>
|
||||
<SongListSkeleton />
|
||||
</div>
|
||||
@@ -372,7 +376,10 @@ export function SongsView() {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Songs</h1>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<MobileSidebarTrigger />
|
||||
<h1 className="text-lg font-semibold">Songs</h1>
|
||||
</div>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Sort songs">
|
||||
|
||||
@@ -49,6 +49,8 @@ function Slider({
|
||||
<SliderPrimitive.Thumb
|
||||
data-slot="slider-thumb"
|
||||
key={index}
|
||||
aria-label={props["aria-label"]}
|
||||
aria-valuetext={props["aria-valuetext"]}
|
||||
className="relative block size-3 shrink-0 rounded-full border border-ring bg-white ring-ring/50 transition-[color,box-shadow] select-none after:absolute after:-inset-2 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 disabled:pointer-events-none disabled:opacity-50"
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { spawn } from "node:child_process"
|
||||
import { createHash } from "node:crypto"
|
||||
import fs from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
import path from "node:path"
|
||||
|
||||
const conversions = new Map<string, Promise<string>>()
|
||||
|
||||
// A completed FLAC file has a duration and supports byte ranges. Piped FLAC does not.
|
||||
export async function seekableLosslessFile(source: string): Promise<string> {
|
||||
if (path.extname(source).toLowerCase() === ".flac") return source
|
||||
|
||||
const stat = await fs.stat(source)
|
||||
const key = createHash("sha256")
|
||||
.update(`${source}:${stat.size}:${stat.mtimeMs}`)
|
||||
.digest("hex")
|
||||
const existing = conversions.get(key)
|
||||
if (existing) return existing
|
||||
|
||||
const conversion = convert(source, key)
|
||||
conversions.set(key, conversion)
|
||||
try {
|
||||
return await conversion
|
||||
} finally {
|
||||
conversions.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
async function convert(source: string, key: string): Promise<string> {
|
||||
const dir = path.join(os.tmpdir(), "otunes-lossless")
|
||||
await fs.mkdir(dir, { recursive: true })
|
||||
const cutoff = Date.now() - 30 * 60 * 1000
|
||||
await Promise.all(
|
||||
(await fs.readdir(dir))
|
||||
.filter((name) => name.endsWith(".flac"))
|
||||
.map(async (name) => {
|
||||
const file = path.join(dir, name)
|
||||
const stat = await fs.stat(file).catch(() => null)
|
||||
if (stat && stat.mtimeMs < cutoff) await fs.rm(file, { force: true })
|
||||
})
|
||||
)
|
||||
const output = path.join(dir, `${key}.flac`)
|
||||
try {
|
||||
await fs.access(output)
|
||||
return output
|
||||
} catch {
|
||||
// Publish only completed conversions so range requests always see a complete file.
|
||||
}
|
||||
const temporary = path.join(
|
||||
await fs.mkdtemp(path.join(dir, "convert-")),
|
||||
"audio.flac"
|
||||
)
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const child = spawn(
|
||||
"ffmpeg",
|
||||
[
|
||||
"-nostdin",
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
source,
|
||||
"-map",
|
||||
"0:a:0",
|
||||
"-c:a",
|
||||
"flac",
|
||||
temporary,
|
||||
],
|
||||
{ stdio: "ignore" }
|
||||
)
|
||||
child.on("error", reject)
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) resolve()
|
||||
else reject(new Error(`Lossless conversion failed: ${code}`))
|
||||
})
|
||||
})
|
||||
await fs.rename(temporary, output)
|
||||
return output
|
||||
} finally {
|
||||
await fs.rm(path.dirname(temporary), { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 324 KiB |
|
Before Width: | Height: | Size: 963 KiB After Width: | Height: | Size: 284 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -538,6 +538,8 @@ export const browseAlbumDetail = query({
|
||||
year: primarySong?.year ?? null,
|
||||
genre: primarySong?.genres[0] ?? null,
|
||||
releaseDate: album.date,
|
||||
hasLossless: songs.some((song) => "lossless" in song.files),
|
||||
hasAtmos: songs.some((song) => "atmos" in song.files),
|
||||
tracks: songs.map((song) => toBrowseAlbumTrack(song, artist.name)),
|
||||
}
|
||||
},
|
||||
@@ -570,6 +572,8 @@ async function browseAlbumSummaryHandler(
|
||||
year: primarySong?.year ?? null,
|
||||
genre: primarySong?.genres[0] ?? null,
|
||||
releaseDate: album.date,
|
||||
hasLossless: songs.some((song) => "lossless" in song.files),
|
||||
hasAtmos: songs.some((song) => "atmos" in song.files),
|
||||
trackCount: songs.length,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ export type BrowseAlbumDetail = BrowseAlbum & {
|
||||
year: number | null
|
||||
genre: string | null
|
||||
releaseDate: string
|
||||
hasLossless: boolean
|
||||
hasAtmos: boolean
|
||||
tracks: BrowseAlbumTrack[]
|
||||
}
|
||||
|
||||
|
||||
@@ -159,3 +159,169 @@ diff --git a/build/Audio.types.d.ts b/build/Audio.types.d.ts
|
||||
+ /** MIME type for streams whose URL has no file extension, such as HLS. */
|
||||
+ mimeType?: string;
|
||||
/**
|
||||
diff --git a/android/src/main/java/expo/modules/audio/BaseAudioPlayer.kt b/android/src/main/java/expo/modules/audio/BaseAudioPlayer.kt
|
||||
--- a/android/src/main/java/expo/modules/audio/BaseAudioPlayer.kt
|
||||
+++ b/android/src/main/java/expo/modules/audio/BaseAudioPlayer.kt
|
||||
@@ -159,8 +159,16 @@
|
||||
super.sharedObjectDidRelease()
|
||||
// Run on GlobalScope (not appContext.mainQueue) so that reloading doesn't cancel the release process
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
- releasePlayer()
|
||||
+ release()
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ private var released = false
|
||||
+
|
||||
+ fun release() {
|
||||
+ if (released) return
|
||||
+ released = true
|
||||
+ releasePlayer()
|
||||
}
|
||||
|
||||
protected open fun releasePlayer() {
|
||||
diff --git a/android/src/main/java/expo/modules/audio/AudioModule.kt b/android/src/main/java/expo/modules/audio/AudioModule.kt
|
||||
--- a/android/src/main/java/expo/modules/audio/AudioModule.kt
|
||||
+++ b/android/src/main/java/expo/modules/audio/AudioModule.kt
|
||||
@@ -1105,6 +1105,7 @@
|
||||
runOnMain {
|
||||
playlist.clearLockScreenControls()
|
||||
playlists.remove(playlist.id)
|
||||
+ playlist.release()
|
||||
releaseAudioFocusIfUnused()
|
||||
}
|
||||
}
|
||||
diff --git a/android/src/main/java/expo/modules/audio/service/MetadataInjectingPlayer.kt b/android/src/main/java/expo/modules/audio/service/MetadataInjectingPlayer.kt
|
||||
--- a/android/src/main/java/expo/modules/audio/service/MetadataInjectingPlayer.kt
|
||||
+++ b/android/src/main/java/expo/modules/audio/service/MetadataInjectingPlayer.kt
|
||||
@@ -1,5 +1,14 @@
|
||||
package expo.modules.audio.service
|
||||
|
||||
+import androidx.media3.common.AudioAttributes
|
||||
+import androidx.media3.common.DeviceInfo
|
||||
+import androidx.media3.common.MediaItem
|
||||
+import androidx.media3.common.PlaybackException
|
||||
+import androidx.media3.common.PlaybackParameters
|
||||
+import androidx.media3.common.Timeline
|
||||
+import androidx.media3.common.TrackSelectionParameters
|
||||
+import androidx.media3.common.Tracks
|
||||
+import androidx.media3.common.VideoSize
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.core.net.toUri
|
||||
@@ -81,7 +90,114 @@
|
||||
|
||||
private inner class MetadataForwardingListener(
|
||||
private val listener: Player.Listener
|
||||
- ) : Player.Listener by listener {
|
||||
+ ) : Player.Listener {
|
||||
+ // Kotlin delegation does not forward Java default methods on Player.Listener.
|
||||
+ // Forward each callback so MediaSession receives timeline and duration changes.
|
||||
+ override fun onTimelineChanged(timeline: Timeline, reason: Int) =
|
||||
+ listener.onTimelineChanged(timeline, reason)
|
||||
+
|
||||
+ override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) =
|
||||
+ listener.onMediaItemTransition(mediaItem, reason)
|
||||
+
|
||||
+ override fun onTracksChanged(tracks: Tracks) =
|
||||
+ listener.onTracksChanged(tracks)
|
||||
+
|
||||
+ override fun onPlaylistMetadataChanged(mediaMetadata: MediaMetadata) =
|
||||
+ listener.onPlaylistMetadataChanged(mediaMetadata)
|
||||
+
|
||||
+ override fun onIsLoadingChanged(isLoading: Boolean) =
|
||||
+ listener.onIsLoadingChanged(isLoading)
|
||||
+
|
||||
+ override fun onLoadingChanged(isLoading: Boolean) =
|
||||
+ listener.onLoadingChanged(isLoading)
|
||||
+
|
||||
+ override fun onAvailableCommandsChanged(availableCommands: Player.Commands) =
|
||||
+ listener.onAvailableCommandsChanged(availableCommands)
|
||||
+
|
||||
+ override fun onTrackSelectionParametersChanged(parameters: TrackSelectionParameters) =
|
||||
+ listener.onTrackSelectionParametersChanged(parameters)
|
||||
+
|
||||
+ override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) =
|
||||
+ listener.onPlayerStateChanged(playWhenReady, playbackState)
|
||||
+
|
||||
+ override fun onPlaybackStateChanged(playbackState: Int) =
|
||||
+ listener.onPlaybackStateChanged(playbackState)
|
||||
+
|
||||
+ override fun onPlayWhenReadyChanged(playWhenReady: Boolean, reason: Int) =
|
||||
+ listener.onPlayWhenReadyChanged(playWhenReady, reason)
|
||||
+
|
||||
+ override fun onPlaybackSuppressionReasonChanged(playbackSuppressionReason: Int) =
|
||||
+ listener.onPlaybackSuppressionReasonChanged(playbackSuppressionReason)
|
||||
+
|
||||
+ override fun onIsPlayingChanged(isPlaying: Boolean) =
|
||||
+ listener.onIsPlayingChanged(isPlaying)
|
||||
+
|
||||
+ override fun onRepeatModeChanged(repeatMode: Int) =
|
||||
+ listener.onRepeatModeChanged(repeatMode)
|
||||
+
|
||||
+ override fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean) =
|
||||
+ listener.onShuffleModeEnabledChanged(shuffleModeEnabled)
|
||||
+
|
||||
+ override fun onPlayerError(error: PlaybackException) =
|
||||
+ listener.onPlayerError(error)
|
||||
+
|
||||
+ override fun onPlayerErrorChanged(error: PlaybackException?) =
|
||||
+ listener.onPlayerErrorChanged(error)
|
||||
+
|
||||
+ override fun onPositionDiscontinuity(reason: Int) =
|
||||
+ listener.onPositionDiscontinuity(reason)
|
||||
+
|
||||
+ override fun onPositionDiscontinuity(oldPosition: Player.PositionInfo, newPosition: Player.PositionInfo, reason: Int) =
|
||||
+ listener.onPositionDiscontinuity(oldPosition, newPosition, reason)
|
||||
+
|
||||
+ override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters) =
|
||||
+ listener.onPlaybackParametersChanged(playbackParameters)
|
||||
+
|
||||
+ override fun onSeekBackIncrementChanged(seekBackIncrementMs: Long) =
|
||||
+ listener.onSeekBackIncrementChanged(seekBackIncrementMs)
|
||||
+
|
||||
+ override fun onSeekForwardIncrementChanged(seekForwardIncrementMs: Long) =
|
||||
+ listener.onSeekForwardIncrementChanged(seekForwardIncrementMs)
|
||||
+
|
||||
+ override fun onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs: Long) =
|
||||
+ listener.onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs)
|
||||
+
|
||||
+ override fun onAudioSessionIdChanged(audioSessionId: Int) =
|
||||
+ listener.onAudioSessionIdChanged(audioSessionId)
|
||||
+
|
||||
+ override fun onAudioAttributesChanged(audioAttributes: AudioAttributes) =
|
||||
+ listener.onAudioAttributesChanged(audioAttributes)
|
||||
+
|
||||
+ override fun onVolumeChanged(volume: Float) =
|
||||
+ listener.onVolumeChanged(volume)
|
||||
+
|
||||
+ override fun onSkipSilenceEnabledChanged(skipSilenceEnabled: Boolean) =
|
||||
+ listener.onSkipSilenceEnabledChanged(skipSilenceEnabled)
|
||||
+
|
||||
+ override fun onDeviceInfoChanged(deviceInfo: DeviceInfo) =
|
||||
+ listener.onDeviceInfoChanged(deviceInfo)
|
||||
+
|
||||
+ override fun onDeviceVolumeChanged(volume: Int, muted: Boolean) =
|
||||
+ listener.onDeviceVolumeChanged(volume, muted)
|
||||
+
|
||||
+ override fun onVideoSizeChanged(videoSize: VideoSize) =
|
||||
+ listener.onVideoSizeChanged(videoSize)
|
||||
+
|
||||
+ override fun onSurfaceSizeChanged(width: Int, height: Int) =
|
||||
+ listener.onSurfaceSizeChanged(width, height)
|
||||
+
|
||||
+ override fun onRenderedFirstFrame() =
|
||||
+ listener.onRenderedFirstFrame()
|
||||
+
|
||||
+ override fun onCues(cues: List<androidx.media3.common.text.Cue>) =
|
||||
+ listener.onCues(cues)
|
||||
+
|
||||
+ override fun onCues(cueGroup: androidx.media3.common.text.CueGroup) =
|
||||
+ listener.onCues(cueGroup)
|
||||
+
|
||||
+ override fun onMetadata(metadata: androidx.media3.common.Metadata) =
|
||||
+ listener.onMetadata(metadata)
|
||||
+
|
||||
override fun onMediaMetadataChanged(mediaMetadata: MediaMetadata) {
|
||||
listener.onMediaMetadataChanged(this@MetadataInjectingPlayer.mediaMetadata)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ settings:
|
||||
|
||||
patchedDependencies:
|
||||
expo-audio@58.0.10:
|
||||
hash: e01ad6e484db76d810c2df5bf9c376eccf8d4c5359736b626868ea8bd8dac566
|
||||
hash: f7f102c0f17b28e763d828acd4f138d62809f5be576e316a13008c27e84968c5
|
||||
path: patches/expo-audio@58.0.10.patch
|
||||
|
||||
importers:
|
||||
@@ -63,7 +63,7 @@ importers:
|
||||
version: 58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3)
|
||||
expo-audio:
|
||||
specifier: ~58.0.10
|
||||
version: 58.0.10(patch_hash=e01ad6e484db76d810c2df5bf9c376eccf8d4c5359736b626868ea8bd8dac566)(expo-asset@58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3))(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)
|
||||
version: 58.0.10(patch_hash=f7f102c0f17b28e763d828acd4f138d62809f5be576e316a13008c27e84968c5)(expo-asset@58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3))(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)
|
||||
expo-blur:
|
||||
specifier: ~58.0.5
|
||||
version: 58.0.5(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)
|
||||
@@ -11073,7 +11073,7 @@ snapshots:
|
||||
- supports-color
|
||||
- typescript
|
||||
|
||||
expo-audio@58.0.10(patch_hash=e01ad6e484db76d810c2df5bf9c376eccf8d4c5359736b626868ea8bd8dac566)(expo-asset@58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3))(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0):
|
||||
expo-audio@58.0.10(patch_hash=f7f102c0f17b28e763d828acd4f138d62809f5be576e316a13008c27e84968c5)(expo-asset@58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3))(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0):
|
||||
dependencies:
|
||||
expo: 58.0.17(@babel/core@7.29.7)(@expo/dom-webview@58.0.2)(@expo/metro-runtime@58.0.15)(expo-router@58.0.25)(react-dom@19.3.0(react@19.3.0))(react-native-worklets@0.13.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3)
|
||||
expo-asset: 58.0.18(expo@58.0.17)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))(react@19.3.0)(typescript@6.0.3)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Export Composer artwork with Xcode, then resize with Pillow.
|
||||
|
||||
Run on macOS with Xcode and Pillow installed: python3 scripts/generate-icons.py
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from PIL import Image
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / "apps/mobile/assets"
|
||||
ICTOOL = "/Applications/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool"
|
||||
|
||||
|
||||
def export(source, output, rendition="Default"):
|
||||
subprocess.run([
|
||||
ICTOOL, str(source), "--export-image", "--output-file", str(output),
|
||||
"--platform", "iOS", "--rendition", rendition,
|
||||
"--width", "1024", "--height", "1024", "--scale", "1",
|
||||
], check=True)
|
||||
return Image.open(output).convert("RGBA")
|
||||
|
||||
|
||||
def save(image, path, size=1024):
|
||||
image.resize((size, size), Image.Resampling.LANCZOS).save(ROOT / path)
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="otunes-icons-") as directory:
|
||||
temp = Path(directory)
|
||||
for variant, composer in [("production", "oTunes"), ("development", "oTunes Dev"), ("preview", "oTunes Preview")]:
|
||||
source = ASSETS / f"{composer}.icon"
|
||||
icon = export(source, temp / "icon.png")
|
||||
dark = export(source, temp / "dark.png", "Dark")
|
||||
suffix = "" if variant == "production" else f"-{variant}"
|
||||
save(icon, f"apps/mobile/assets/icon{suffix}.png")
|
||||
|
||||
# Android uses the Composer artwork without Apple's rounded glass base.
|
||||
document = json.loads((source / "icon.json").read_text())
|
||||
layer = document["groups"][0]["layers"][0]
|
||||
artwork = Image.open(source / "Assets" / layer["image-name"]).convert("RGBA")
|
||||
position = layer["position"]
|
||||
scale = position["scale"]
|
||||
artwork = artwork.resize(tuple(round(size * scale) for size in artwork.size), Image.Resampling.LANCZOS)
|
||||
x, y = position["translation-in-points"]
|
||||
foreground = Image.new("RGBA", (1024, 1024))
|
||||
foreground.alpha_composite(artwork, (round((1024 - artwork.width) / 2 + x), round((1024 - artwork.height) / 2 + y)))
|
||||
# Android's adaptive canvas includes an outer area reserved for motion.
|
||||
adaptive = Image.new("RGBA", (1024, 1024))
|
||||
adaptive.alpha_composite(foreground.resize((682, 682), Image.Resampling.LANCZOS), (171, 171))
|
||||
save(adaptive, f"apps/mobile/assets/android-icon-foreground{suffix}.png")
|
||||
# Use the rendered background's center column to retain Composer colors.
|
||||
background_source = temp / "background.icon"
|
||||
shutil.copytree(source, background_source, dirs_exist_ok=True)
|
||||
document = json.loads((source / "icon.json").read_text())
|
||||
document["groups"] = []
|
||||
(background_source / "icon.json").write_text(json.dumps(document))
|
||||
background = export(background_source, temp / "background.png")
|
||||
background = background.crop((512, 0, 513, 1024)).resize((1024, 1024))
|
||||
save(background, f"apps/mobile/assets/android-icon-background{suffix}.png")
|
||||
save(Image.alpha_composite(background, foreground), f"apps/mobile/assets/android-icon{suffix}.png")
|
||||
if variant != "production":
|
||||
continue
|
||||
monochrome = Image.new("RGBA", adaptive.size, "white")
|
||||
monochrome.putalpha(adaptive.getchannel("A"))
|
||||
save(monochrome, "apps/mobile/assets/android-icon-monochrome.png")
|
||||
for name, image in [("icon-dark", dark), ("ios-icon", icon), ("ios-icon-dark", dark)]:
|
||||
save(image, f"apps/mobile/assets/{name}.png")
|
||||
for name, image in [("logo", icon), ("logo-dark", dark)]:
|
||||
save(image, f"apps/web/public/{name}.png")
|
||||
for path, size, image in [
|
||||
("favicon.png", 64, icon),
|
||||
("apps/mobile/assets/favicon.png", 64, icon),
|
||||
("apps/web/app/favicon.png", 128, icon),
|
||||
("apps/web/public/favicon.png", 128, icon),
|
||||
("apps/web/public/favicon-dark.png", 128, dark),
|
||||
]:
|
||||
save(image, path, size)
|
||||