fixed: 视频播放时调整顺寻影响播放状态

This commit is contained in:
LittleBoy 2025-02-06 16:17:06 +08:00 committed by Coding
parent 829a135ef3
commit 2c1ea4a31a
3 changed files with 30 additions and 14 deletions

View File

@ -11,6 +11,14 @@
- name: build - name: build
script: yarn run build script: yarn run build
dev/main:
push:
- <<: *pipeline
main:
push:
- <<: *pipeline
release: release:
push: push:
- <<: *pipeline - <<: *pipeline

View File

@ -17,6 +17,7 @@ import InfiniteScroller, {InfiniteScrollerRef} from "@/components/scoller/infini
import {IconDelete} from "@/components/icons"; import {IconDelete} from "@/components/icons";
import {useLocation} from "react-router-dom"; import {useLocation} from "react-router-dom";
import {useTranslation} from "react-i18next"; import {useTranslation} from "react-i18next";
import {find} from "lodash";
export default function VideoIndex() { export default function VideoIndex() {
const {t} = useTranslation() const {t} = useTranslation()
@ -27,14 +28,15 @@ export default function VideoIndex() {
const scrollerRef = useRef<InfiniteScrollerRef | null>(null) const scrollerRef = useRef<InfiniteScrollerRef | null>(null)
const [state, setState] = useSetState({ const [state, setState] = useSetState({
checkedAll: false, checkedAll: false,
playingIndex: -1, playingId: -1,
showToTop: false, showToTop: false,
showStatePos: false, showStatePos: false,
playState: { playState: {
current: -1, current: -1,
total: -1 total: -1
}, },
loading:false loading:false,
playVideoUrl: ''
}) })
const [checkedIdArray, setCheckedIdArray] = useState<Id[]>([]) const [checkedIdArray, setCheckedIdArray] = useState<Id[]>([])
const [refreshTimer,setTimer] = useState(0) const [refreshTimer,setTimer] = useState(0)
@ -52,7 +54,7 @@ export default function VideoIndex() {
setVideoData(list) setVideoData(list)
if (needReset) { if (needReset) {
setCheckedIdArray([]) setCheckedIdArray([])
setState({checkedAll: false, playingIndex: -1}) setState({checkedAll: false, playingId: -1})
} }
// 判断是否有生成中的视频 // 判断是否有生成中的视频
if (list.filter(s => s.status == VideoStatus.Generating).length > 0) { if (list.filter(s => s.status == VideoStatus.Generating).length > 0) {
@ -73,10 +75,11 @@ export default function VideoIndex() {
} }
// 播放视频 // 播放视频
const playVideo = (video: VideoInfo, playingIndex: number) => { const playVideo = (video: VideoInfo) => {
if (state.playingIndex == playingIndex) { console.log('play video',video)
if (state.playingId == video.id) {
player.current?.pause(); player.current?.pause();
setState({playingIndex: -1}) setState({playingId: -1})
return; return;
} }
if (video.status == VideoStatus.Generating) return; if (video.status == VideoStatus.Generating) return;
@ -84,7 +87,7 @@ export default function VideoIndex() {
// player.current?.play('https://staticplus.gachafun.com/ai-collect/composite_video/2024-12-17/1186196465916190720.flv', 30) // player.current?.play('https://staticplus.gachafun.com/ai-collect/composite_video/2024-12-17/1186196465916190720.flv', 30)
// //
if (video.oss_video_url && video.status !== 1) { if (video.oss_video_url && video.status !== 1) {
setState({playingIndex}) setState({playingId: video.id})
player.current?.play(video.oss_video_url, 0) player.current?.play(video.oss_video_url, 0)
} }
} }
@ -116,12 +119,13 @@ export default function VideoIndex() {
useEffect(loadList, []) useEffect(loadList, [])
const totalDuration = useMemo(() => { const totalDuration = useMemo(() => {
if (!videoData || videoData.length == 0) return 0; if (!videoData || videoData.length == 0) return 0;
if (state.playingIndex == -1 || state.playingIndex >= videoData.length) return 0 const v = state.playingId == -1 ? null : videoData.find(s=>s.id == state.playingId)
const v = videoData[state.playingIndex] as VideoInfo; if (!v) return 0
//const v = videoData[state.playingIndex] as VideoInfo;
return Math.ceil(v.duration / 1000) return Math.ceil(v.duration / 1000)
// 计算总时长 // 计算总时长
//return videoData.reduce((sum, v) => sum + Math.ceil(v.duration / 1000), 0); //return videoData.reduce((sum, v) => sum + Math.ceil(v.duration / 1000), 0);
}, [videoData, state.playingIndex]) }, [videoData, state.playingId])
useEffect(() => { useEffect(() => {
if (loc.state == 'push-success' && !state.showStatePos && videoData.length && scrollerRef.current) { if (loc.state == 'push-success' && !state.showStatePos && videoData.length && scrollerRef.current) {
@ -147,10 +151,11 @@ export default function VideoIndex() {
<div className="text-center text-base text-gray-400">{t("generating.title")}</div> <div className="text-center text-base text-gray-400">{t("generating.title")}</div>
<div className="video-player flex items-center mt-2"> <div className="video-player flex items-center mt-2">
<div className=" w-[360px] h-[636px] rounded overflow-hidden"> <div className=" w-[360px] h-[636px] rounded overflow-hidden">
{/*videoData[state.playingIndex]?.oss_video_url*/}
<Player <Player
ref={player} url={videoData[state.playingIndex]?.oss_video_url} ref={player}
url={state.playVideoUrl}
onChange={(state) => { onChange={(state) => {
console.log(state)
if (state.end || state.error) setState({playingIndex: -1}) if (state.end || state.error) setState({playingIndex: -1})
}} }}
onProgress={(current, duration) => { onProgress={(current, duration) => {
@ -229,7 +234,7 @@ export default function VideoIndex() {
key={index} key={index}
type={'create'} type={'create'}
active={checkedIdArray.includes(v.id)} active={checkedIdArray.includes(v.id)}
playing={state.playingIndex == index} playing={state.playingId == v.id}
checked={checkedIdArray.includes(v.id)} checked={checkedIdArray.includes(v.id)}
className={`list-item-${index} mt-3 mb-2 list-item-state-${v.status}`} className={`list-item-${index} mt-3 mb-2 list-item-state-${v.status}`}
onCheckedChange={(checked) => { onCheckedChange={(checked) => {
@ -239,7 +244,7 @@ export default function VideoIndex() {
return newArr; return newArr;
}) })
}} }}
onItemClick={() => playVideo(v, index)} onItemClick={() => playVideo(v)}
onRemove={() => processDeleteVideo([v.id])} onRemove={() => processDeleteVideo([v.id])}
onEdit={v.status == VideoStatus.Generating ? undefined : () => { onEdit={v.status == VideoStatus.Generating ? undefined : () => {
setEditId(v.article_id) setEditId(v.article_id)

3
src/types/api.d.ts vendored
View File

@ -101,6 +101,9 @@ declare interface VideoInfo {
publish_time?: number|string; publish_time?: number|string;
ctime?: number|string; ctime?: number|string;
} }
declare interface VideoListItem extends VideoInfo {
playing?: boolean;
}
// room live // room live
declare interface LiveVideoInfo { declare interface LiveVideoInfo {
id: number; id: number;