Now Playing Bar
Compact current-media bar with separate details and play/pause actions, optional progress and bounded seek controls.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add now-playing-barSource files
Expand a file to read the source the installer copies into your app.
components/blocks/now-playing-bar/NowPlayingBar.tsx
import type { ReactNode } from 'react'
import { I18nManager, View, type ViewProps } from 'react-native'
import { ChevronLeft, ChevronRight, FastForward, Pause, Play, Rewind } from 'lucide-react-native'
import { Icon } from '@/components/ui/icon'
import { IconButton } from '@/components/ui/icon-button'
import { ListItem, ListItemContent, ListItemDescription, ListItemTitle } from '@/components/ui/list'
import { Progress } from '@/components/ui/progress'
import { Text } from '@/components/ui/text'
import { cn } from '@/lib/utils'
const defaultLabels = {
play: 'Play',
pause: 'Pause',
loading: 'Loading playback…',
details: 'Open playback details',
progress: 'Playback progress',
elapsed: (position: string, duration: string) => `${position} of ${duration}`,
back: (seconds: number) => `Back ${seconds} seconds`,
forward: (seconds: number) => `Forward ${seconds} seconds`,
}
export interface NowPlayingBarProps extends Omit<ViewProps, 'children'> {
className?: string
title: string
subtitle?: string
artwork?: ReactNode
status?: 'paused' | 'playing' | 'loading'
/** Media position and duration in seconds. A known duration enables the progress row. */
position?: number
duration?: number
onPlay?: () => void
onPause?: () => void
onOpenDetails?: () => void
/** Requests an absolute seek in seconds using the two visible jump controls. */
onSeek?: (position: number) => void
seekSeconds?: number
labels?: Partial<typeof defaultLabels>
}
function timestamp(seconds: number) {
return `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, '0')}`
}
export function NowPlayingBar({
title,
subtitle,
artwork,
status = 'paused',
position = 0,
duration = 0,
onPlay,
onPause,
onOpenDetails,
onSeek,
seekSeconds = 10,
labels,
className,
...props
}: NowPlayingBarProps) {
const copy = { ...defaultLabels, ...labels }
const playing = status === 'playing'
const loading = status === 'loading'
const onToggle = playing ? onPause : onPlay
const playbackLabel = loading ? copy.loading : playing ? copy.pause : copy.play
const hasDuration = Number.isFinite(duration) && duration > 0
const cursor = hasDuration && Number.isFinite(position) ? Math.max(0, Math.min(position, duration)) : 0
const progress = hasDuration ? Math.round((cursor / duration) * 100) : 0
const elapsed = hasDuration ? copy.elapsed(timestamp(cursor), timestamp(duration)) : undefined
const step = Number.isFinite(seekSeconds) && seekSeconds > 0 ? seekSeconds : 10
return (
<View {...props} className={cn('gap-[4px] rounded-lg border border-border bg-card px-[8px] py-[4px]', className)}>
<View className="flex-row items-center gap-[4px]">
<ListItem
className="min-w-0 flex-1 rounded-md px-[8px] py-[4px]"
onPress={onOpenDetails ? () => onOpenDetails() : undefined}
accessibilityLabel={onOpenDetails ? [title, subtitle].filter(Boolean).join(', ') : undefined}
accessibilityHint={onOpenDetails ? copy.details : undefined}
>
{artwork ? (
<View aria-hidden pointerEvents="none" className="shrink-0 overflow-hidden rounded-md">
{artwork}
</View>
) : null}
<ListItemContent>
<ListItemTitle numberOfLines={onOpenDetails ? 1 : undefined}>{title}</ListItemTitle>
{subtitle ? (
<ListItemDescription numberOfLines={onOpenDetails ? 1 : undefined}>{subtitle}</ListItemDescription>
) : null}
</ListItemContent>
{onOpenDetails ? (
<Icon icon={I18nManager.isRTL ? ChevronLeft : ChevronRight} size={16} className="text-muted-foreground" />
) : null}
</ListItem>
{onToggle ? (
<IconButton
icon={playing ? Pause : Play}
accessibilityLabel={playbackLabel}
loading={loading}
onPress={() => {
if (!loading) onToggle()
}}
/>
) : null}
</View>
{hasDuration ? (
<View className="gap-[2px] px-[8px] pb-[2px]">
<Progress
value={progress}
accessibilityLabel={copy.progress}
accessibilityValue={{ min: 0, max: 100, now: progress, text: elapsed }}
/>
<View className="flex-row flex-wrap items-center justify-between gap-[4px]">
{onSeek ? (
<IconButton
icon={Rewind}
iconSize={17}
accessibilityLabel={copy.back(step)}
disabled={loading || cursor <= 0}
onPress={() => {
if (!loading && cursor > 0) onSeek(Math.max(0, cursor - step))
}}
/>
) : null}
<Text size="xs" variant="muted" style={{ fontVariant: ['tabular-nums'] }} aria-hidden>
{elapsed}
</Text>
{onSeek ? (
<IconButton
icon={FastForward}
iconSize={17}
accessibilityLabel={copy.forward(step)}
disabled={loading || cursor >= duration}
onPress={() => {
if (!loading && cursor < duration) onSeek(Math.min(duration, cursor + step))
}}
/>
) : null}
</View>
</View>
) : null}
</View>
)
}
components/blocks/now-playing-bar/index.ts
export { NowPlayingBar, type NowPlayingBarProps } from './NowPlayingBar'