import React, { useState } from 'react' import { Play, Pause, Music, Trash2, BarChart3, Clock, HardDrive, Hash } from 'lucide-react' import { AudioFile, AudioService } from '../services/audioService' interface AudioCardProps { audio: AudioFile onDelete: (audioId: string) => void onShowChart: (audio: AudioFile) => void } const AudioCard: React.FC = ({ audio, onDelete, onShowChart }) => { const [isPlaying, setIsPlaying] = useState(false) const [audioElement, setAudioElement] = useState(null) const handlePlayPause = () => { if (!audioElement) { // 创建音频元素 const audio_el = new Audio(`file://${audio.file_path}`) audio_el.addEventListener('ended', () => setIsPlaying(false)) audio_el.addEventListener('error', (e) => { console.error('Audio playback error:', e) setIsPlaying(false) }) setAudioElement(audio_el) audio_el.play() .then(() => setIsPlaying(true)) .catch(err => { console.error('Failed to play audio:', err) setIsPlaying(false) }) } else { if (isPlaying) { audioElement.pause() setIsPlaying(false) } else { audioElement.play() .then(() => setIsPlaying(true)) .catch(err => { console.error('Failed to play audio:', err) setIsPlaying(false) }) } } } const handleDelete = () => { if (audioElement) { audioElement.pause() setAudioElement(null) setIsPlaying(false) } onDelete(audio.id) } return (
{/* 音频信息头部 */}

{audio.filename}

{audio.format.toUpperCase()} • {AudioService.formatDuration(audio.duration)}

{/* 播放按钮 */}
{/* 音频详细信息 */}
{/* 基本信息 */}
时长: {AudioService.formatDuration(audio.duration)}
大小: {AudioService.formatFileSize(audio.file_size)}
{/* 音频参数 */}
采样率: {audio.sample_rate} Hz
声道: {audio.channels}
{/* 节奏信息 */} {audio.tempo && (
节拍: {audio.tempo.toFixed(1)} BPM
)} {/* 频谱特征 */} {audio.spectral_centroid && (
频谱重心: {audio.spectral_centroid.toFixed(0)} Hz
{audio.zero_crossing_rate && (
过零率: {(audio.zero_crossing_rate * 100).toFixed(2)}%
)}
)} {/* MD5哈希 */}
MD5: {audio.md5_hash.substring(0, 8)}...
{/* 操作按钮 */}
{new Date(audio.created_at).toLocaleDateString()}
{/* 频率图按钮 */} {audio.frequency_chart_path && ( )} {/* 删除按钮 */}
) } export default AudioCard