|
| 1 | +import { formatFileSize, formatTime } from '@flow/core' |
| 2 | +import { useDisplayTrack } from '@flow/player' |
| 3 | +import { Image, StyleSheet, View } from 'react-native' |
| 4 | +import { Text } from 'react-native-paper' |
| 5 | +import Animated from 'react-native-reanimated' |
| 6 | +import { usePlayerContext } from './Context' |
| 7 | + |
| 8 | +export default function TrackInfo() { |
| 9 | + const { artworkColors } = usePlayerContext() |
| 10 | + const displayTrack = useDisplayTrack() |
| 11 | + |
| 12 | + return ( |
| 13 | + <Animated.ScrollView |
| 14 | + style={styles.rootContainer} |
| 15 | + showsVerticalScrollIndicator={false} |
| 16 | + contentContainerStyle={styles.container} |
| 17 | + > |
| 18 | + <View style={[styles.group, { backgroundColor: `${artworkColors.background}20` }]}> |
| 19 | + <Text style={styles.header}>音频信息</Text> |
| 20 | + <View style={styles.audioSingleRow}> |
| 21 | + <View style={styles.audioCompactCard}> |
| 22 | + <Text style={styles.audioCompactLabel}>格式</Text> |
| 23 | + <Text style={styles.audioCompactValue}>{displayTrack?.format?.toUpperCase() || '--'}</Text> |
| 24 | + </View> |
| 25 | + <View style={styles.audioCompactCard}> |
| 26 | + <Text style={styles.audioCompactLabel}>声道</Text> |
| 27 | + <Text style={styles.audioCompactValue}>{displayTrack?.channels || '--'}</Text> |
| 28 | + </View> |
| 29 | + <View style={styles.audioCompactCard}> |
| 30 | + <Text style={styles.audioCompactLabel}>比特率</Text> |
| 31 | + <Text style={styles.audioCompactValue}> |
| 32 | + {displayTrack?.bitrate ? `${displayTrack.bitrate}kbps` : '--'} |
| 33 | + </Text> |
| 34 | + </View> |
| 35 | + <View style={styles.audioCompactCard}> |
| 36 | + <Text style={styles.audioCompactLabel}>采样率</Text> |
| 37 | + <Text style={styles.audioCompactValue}> |
| 38 | + {displayTrack?.sampleRate ? `${displayTrack.sampleRate}hz` : '--'} |
| 39 | + </Text> |
| 40 | + </View> |
| 41 | + </View> |
| 42 | + </View> |
| 43 | + |
| 44 | + <View style={[styles.group, { backgroundColor: `${artworkColors.background}20` }]}> |
| 45 | + <Text style={styles.header}>专辑</Text> |
| 46 | + <View style={styles.content}> |
| 47 | + <Image |
| 48 | + source={{ uri: displayTrack?.artwork }} |
| 49 | + style={styles.albumArtwork} |
| 50 | + /> |
| 51 | + <Text>{displayTrack?.album}</Text> |
| 52 | + </View> |
| 53 | + </View> |
| 54 | + |
| 55 | + <View style={[styles.group, { backgroundColor: `${artworkColors.background}20` }]}> |
| 56 | + <Text style={styles.header}>艺术家</Text> |
| 57 | + <View style={styles.content}> |
| 58 | + <Text>{displayTrack?.artist}</Text> |
| 59 | + </View> |
| 60 | + </View> |
| 61 | + |
| 62 | + <View style={[styles.group, { backgroundColor: `${artworkColors.background}20` }]}> |
| 63 | + <Text style={styles.header}>文件信息</Text> |
| 64 | + |
| 65 | + <View style={styles.fileInfoItem}> |
| 66 | + <Text style={styles.label}>文件路径</Text> |
| 67 | + <Text style={styles.pathText} numberOfLines={2} ellipsizeMode="middle"> |
| 68 | + {displayTrack?.url} |
| 69 | + </Text> |
| 70 | + </View> |
| 71 | + <View style={styles.fileInfoItem}> |
| 72 | + <Text style={styles.label}>文件大小</Text> |
| 73 | + <Text style={styles.value}>{formatFileSize(displayTrack?.fileSize ?? 0)}</Text> |
| 74 | + </View> |
| 75 | + <View style={styles.fileInfoItem}> |
| 76 | + <Text style={styles.label}>创建时间</Text> |
| 77 | + <Text style={styles.value}>{formatTime(displayTrack?.createdAt)}</Text> |
| 78 | + </View> |
| 79 | + <View style={[styles.fileInfoItem, { marginBottom: 0 }]}> |
| 80 | + <Text style={styles.label}>修改时间</Text> |
| 81 | + <Text style={styles.value}>{formatTime(displayTrack?.modifiedAt)}</Text> |
| 82 | + </View> |
| 83 | + </View> |
| 84 | + </Animated.ScrollView> |
| 85 | + ) |
| 86 | +} |
| 87 | + |
| 88 | +const styles = StyleSheet.create({ |
| 89 | + rootContainer: { |
| 90 | + flex: 1, |
| 91 | + marginVertical: 16, |
| 92 | + }, |
| 93 | + container: { |
| 94 | + paddingHorizontal: 28, |
| 95 | + flex: 1, |
| 96 | + justifyContent: 'center', |
| 97 | + gap: 12, |
| 98 | + }, |
| 99 | + group: { |
| 100 | + padding: 12, |
| 101 | + borderRadius: 12, |
| 102 | + overflow: 'hidden', |
| 103 | + }, |
| 104 | + header: { |
| 105 | + marginBottom: 10, |
| 106 | + fontSize: 14, |
| 107 | + fontWeight: '600', |
| 108 | + letterSpacing: 0.2, |
| 109 | + }, |
| 110 | + content: { |
| 111 | + flexDirection: 'row', |
| 112 | + alignItems: 'center', |
| 113 | + gap: 8, |
| 114 | + }, |
| 115 | + audioSingleRow: { |
| 116 | + flexDirection: 'row', |
| 117 | + gap: 4, |
| 118 | + }, |
| 119 | + audioCompactCard: { |
| 120 | + flex: 1, |
| 121 | + backgroundColor: 'rgba(255, 255, 255, 0.05)', |
| 122 | + paddingVertical: 5, |
| 123 | + paddingHorizontal: 4, |
| 124 | + borderRadius: 4, |
| 125 | + alignItems: 'center', |
| 126 | + minHeight: 36, |
| 127 | + justifyContent: 'center', |
| 128 | + }, |
| 129 | + audioCompactLabel: { |
| 130 | + fontSize: 9, |
| 131 | + fontWeight: '500', |
| 132 | + opacity: 0.6, |
| 133 | + marginBottom: 1, |
| 134 | + textAlign: 'center', |
| 135 | + textTransform: 'uppercase', |
| 136 | + letterSpacing: 0.2, |
| 137 | + }, |
| 138 | + audioCompactValue: { |
| 139 | + fontSize: 11, |
| 140 | + fontWeight: '600', |
| 141 | + textAlign: 'center', |
| 142 | + lineHeight: 14, |
| 143 | + }, |
| 144 | + fileInfoItem: { |
| 145 | + marginBottom: 8, |
| 146 | + }, |
| 147 | + label: { |
| 148 | + fontSize: 11, |
| 149 | + fontWeight: '500', |
| 150 | + opacity: 0.7, |
| 151 | + marginBottom: 2, |
| 152 | + }, |
| 153 | + value: { |
| 154 | + fontSize: 13, |
| 155 | + lineHeight: 18, |
| 156 | + }, |
| 157 | + pathText: { |
| 158 | + fontSize: 13, |
| 159 | + lineHeight: 15, |
| 160 | + }, |
| 161 | + albumArtwork: { |
| 162 | + width: 38, |
| 163 | + height: 38, |
| 164 | + borderRadius: 4, |
| 165 | + }, |
| 166 | +}) |
0 commit comments