feat: 匹配素材成功后自动加载播放预览
This commit is contained in:
@@ -10,7 +10,7 @@ export interface UseEmptyShotMaterialsResult {
|
||||
materialMatchMap: Record<string, { url: string; duration: number } | null>;
|
||||
userUploadedMaterials: Record<string, { path: string; duration: number }>;
|
||||
matchMaterials: () => Promise<void>;
|
||||
matchSingleMaterial: (shotId: string) => Promise<void>;
|
||||
matchSingleMaterial: (shotId: string) => Promise<{ url: string; duration: number } | null>;
|
||||
switchMaterial: (shotId: string) => Promise<{ url: string; duration: number } | null>;
|
||||
uploadMaterial: (shotId: string) => Promise<{ path: string; duration: number } | null>;
|
||||
setMaterialMatchMap: React.Dispatch<
|
||||
@@ -96,11 +96,14 @@ export function useEmptyShotMaterials(
|
||||
|
||||
/**
|
||||
* 单个镜头素材匹配
|
||||
* @returns 匹配结果或 null
|
||||
*/
|
||||
const matchSingleMaterial = async (shotId: string) => {
|
||||
const matchSingleMaterial = async (
|
||||
shotId: string
|
||||
): Promise<{ url: string; duration: number } | null> => {
|
||||
const shot = shots.find((s) => String(s.id) === shotId);
|
||||
if (!shot || shot.type !== 'empty_shot' || !shot.scene) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
const assignedMap = computeAssignedIntervals(shots);
|
||||
@@ -116,10 +119,12 @@ export function useEmptyShotMaterials(
|
||||
if (!result) {
|
||||
toast.warning('暂无可用素材');
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
console.error('[VideoGeneration] 素材匹配失败:', err);
|
||||
toast.error(err instanceof Error ? err.message : '素材匹配失败');
|
||||
setMaterialMatchMap((prev) => ({ ...prev, [shotId]: null }));
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -322,7 +322,10 @@ export default function VideoGeneration() {
|
||||
|
||||
// 处理素材匹配(单个镜头触发匹配)
|
||||
const handleMatchMaterial = async (shotId: string) => {
|
||||
await matchSingleMaterial(shotId);
|
||||
const result = await matchSingleMaterial(shotId);
|
||||
if (result && Number(shotId) === activeScene) {
|
||||
setPreviewVideoUrl(result.url);
|
||||
}
|
||||
};
|
||||
|
||||
const activeShot = shots.find((s) => Number(s.id) === activeScene);
|
||||
|
||||
Reference in New Issue
Block a user