diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 4fe7a7e..49392c4 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -39,6 +39,7 @@ pub fn run() { commands::system_commands::select_directory, commands::system_commands::select_file, commands::system_commands::open_file_directory, + commands::system_commands::play_video_segment, commands::system_commands::get_app_info, commands::system_commands::validate_directory, commands::system_commands::get_directory_name, diff --git a/apps/desktop/src-tauri/src/presentation/commands/system_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/system_commands.rs index e173548..f251202 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/system_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/system_commands.rs @@ -245,3 +245,47 @@ pub async fn open_file_directory(file_path: String) -> Result<(), String> { } } } + +/// 播放视频片段命令 +#[command] +pub async fn play_video_segment(file_path: String, start_time: f64, end_time: f64) -> Result<(), String> { + use std::path::Path; + use std::process::Command; + + let path = Path::new(&file_path); + + // 检查文件是否存在 + if !path.exists() { + return Err("视频文件不存在".to_string()); + } + + // 根据操作系统使用不同的播放器 + let result = if cfg!(target_os = "windows") { + // Windows: 尝试使用系统默认播放器 + Command::new("cmd") + .args(["/C", "start", "", &file_path]) + .spawn() + } else if cfg!(target_os = "macos") { + // macOS: 使用 open 命令 + Command::new("open") + .arg(&file_path) + .spawn() + } else { + // Linux: 使用 xdg-open + Command::new("xdg-open") + .arg(&file_path) + .spawn() + }; + + match result { + Ok(_) => { + info!("成功启动视频播放: {} ({}s - {}s)", file_path, start_time, end_time); + Ok(()) + } + Err(e) => { + let error_msg = format!("播放视频失败: {}", e); + tracing::error!("{}", error_msg); + Err(error_msg) + } + } +} diff --git a/apps/desktop/src/components/MaterialSegmentView.tsx b/apps/desktop/src/components/MaterialSegmentView.tsx index 3b73410..e5532ee 100644 --- a/apps/desktop/src/components/MaterialSegmentView.tsx +++ b/apps/desktop/src/components/MaterialSegmentView.tsx @@ -93,6 +93,19 @@ const openFileDirectory = async (filePath: string) => { } }; +// 播放视频片段 +const playVideoSegment = async (filePath: string, startTime: number, endTime: number) => { + try { + await invoke('play_video_segment', { + filePath, + startTime, + endTime + }); + } catch (error) { + console.error('播放视频失败:', error); + } +}; + /** * 素材片段管理组件 - 多条件检索标签页风格 */ @@ -257,7 +270,15 @@ export const MaterialSegmentView: React.FC = ({ projec {/* 操作按钮 */}
-