Something went wrong. Try again.
An AI-music permissible frontend for plyr.fm.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117import { View, Text, Pressable, Image, StyleSheet } from 'react-native';import { useState, useEffect } from 'react';import { useRouter } from 'expo-router';import { subscribe, togglePlayback, playNext, playPrevious, getPlayerState } from '../lib/player';import { Colors, Spacing, Typography } from '../constants/theme';
export default function MiniPlayer() { const router = useRouter(); const [state, setState] = useState(getPlayerState());
useEffect(() => { const unsub = subscribe(setState); return unsub; }, []);
if (!state.trackId) return null;
return ( <Pressable onPress={() => router.push('/now-playing')} style={[styles.container, { backgroundColor: Colors.surface }]} > {/* Thumbnail */} {state.imageUrl ? ( <Image source={{ uri: state.imageUrl }} style={styles.thumbnail} /> ) : ( <View style={[styles.thumbnail, { backgroundColor: Colors.surfaceHover, justifyContent: 'center', alignItems: 'center' }]}> <Text style={{ color: Colors.textSecondary, fontSize: 14 }}>♫</Text> </View> )}
{/* Track info */} <View style={styles.info}> <Text numberOfLines={1} style={[Typography.subheading, { color: Colors.text, fontSize: 14 }]}> {state.title} </Text> <Text numberOfLines={1} style={[Typography.tiny, { color: Colors.textSecondary }]}> {state.artist} </Text> </View>
{/* Skip controls */} {state.queue.length > 1 && ( <Pressable onPress={(e) => { e.stopPropagation(); playPrevious(); }} style={[styles.skipButton, { opacity: state.hasPrevious ? 1 : 0.3 }]} disabled={!state.hasPrevious} > <Text style={{ color: Colors.textSecondary, fontSize: 12 }}>⏮</Text> </Pressable> )}
{/* Play/pause */} <Pressable onPress={(e) => { e.stopPropagation(); togglePlayback(); }} style={[styles.playButton, { backgroundColor: state.isPlaying ? Colors.playing : Colors.ai }]} > <Text style={{ color: '#fff', fontSize: 14, fontWeight: '700' }}> {state.isPlaying ? '⏸' : '▶'} </Text> </Pressable>
{state.queue.length > 1 && ( <Pressable onPress={(e) => { e.stopPropagation(); playNext(); }} style={[styles.skipButton, { opacity: state.hasNext ? 1 : 0.3 }]} disabled={!state.hasNext} > <Text style={{ color: Colors.textSecondary, fontSize: 12 }}>⏭</Text> </Pressable> )}
{/* Queue indicator */} {state.queue.length > 1 && ( <Text style={[Typography.tiny, { color: Colors.textSecondary, fontSize: 9 }]}> {state.queueIndex + 1}/{state.queue.length} </Text> )} </Pressable> );}
const styles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: Spacing.md, paddingVertical: Spacing.sm, borderTopWidth: 1, borderTopColor: Colors.border, gap: Spacing.sm, }, thumbnail: { width: 40, height: 40, borderRadius: 8, }, info: { flex: 1, justifyContent: 'center', }, playButton: { width: 36, height: 36, borderRadius: 18, justifyContent: 'center', alignItems: 'center', }, skipButton: { width: 28, height: 28, borderRadius: 14, justifyContent: 'center', alignItems: 'center', },});