From a2770765d870d12fbbfae2a5a4007164fe73f16a Mon Sep 17 00:00:00 2001 From: callmeyan Date: Tue, 17 Dec 2024 19:57:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=99=A8;=E6=B7=BB=E5=8A=A0=E5=8E=86=E5=8F=B2=E8=A7=86?= =?UTF-8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/core.scss | 2 + src/components/video/player.tsx | 71 +++++++++-------- src/pages/library/components/search-form.tsx | 46 ++++------- src/pages/library/components/video-item.tsx | 10 ++- src/pages/library/index.tsx | 35 +++++++-- src/pages/live/index.tsx | 81 +++++++------------- src/pages/video/index.tsx | 6 +- src/service/api/video.ts | 4 +- src/types/api.d.ts | 6 ++ src/util/strings.ts | 1 + 10 files changed, 132 insertions(+), 130 deletions(-) diff --git a/src/assets/core.scss b/src/assets/core.scss index 5a28cde..1263292 100644 --- a/src/assets/core.scss +++ b/src/assets/core.scss @@ -160,8 +160,10 @@ } .video-player{ .video-js{ + @apply w-full h-full; max-width: 100%; max-height: 100%; + background:#fff; // hsl(210, 100%, 48%) } } diff --git a/src/components/video/player.tsx b/src/components/video/player.tsx index e6f399f..99d88d5 100644 --- a/src/components/video/player.tsx +++ b/src/components/video/player.tsx @@ -20,6 +20,7 @@ type StateUpdate = Partial | ((prev: State) => Partial) type Props = { url?: string; cover?: string; showControls?: boolean; className?: string; onChange?: (state: State) => void; + muted?: boolean; } export type PlayerInstance = { play: (url: string, currentTime: number) => void; @@ -47,39 +48,52 @@ export const Player = React.forwardRef((props, ref) => { }) } useEffect(() => { + const playerVideo = document.createElement('video'); + const playerId = `player-container-${Date.now().toString(16)}`; + playerVideo.setAttribute('id', playerId) + playerVideo.setAttribute('preload', 'auto') + playerVideo.setAttribute('playsInline', 'true') + playerVideo.setAttribute('webkit-playsinline', 'true') + if(props.className) playerVideo.setAttribute('className', props.className) + document.querySelector('.video-player-container-inner').appendChild(playerVideo) + + const player = TCPlayer(playerId, { + //sources: [{src: props.url}], + controls: props.showControls, + // muted:props.muted, + autoplay: true, + licenseUrl: 'https://license.vod2.myqcloud.com/license/v2/1328581896_1/v_cube.license' + } + ) + player.on('pause', () => { + setState({playing: false, end: false, error: false}) + }) + player.on('playing', () => { + setState({playing: true, end: false, error: false}) + }) + player.on('ended', () => { + setState({end: true, playing: false, error: false}) + }) + player.on('error', () => { + setState({end: false, playing: false, error: true}) + }) + setTcPlayer(() => player) return () => { - if (tcPlayer) tcPlayer.unload() + if (tcPlayer) { + tcPlayer.pause() + tcPlayer.unload() + } } }, []) React.useImperativeHandle(ref, () => { return { play: (url, currentTime = 0) => { - const player = tcPlayer || TCPlayer( - 'player-container-id', - { - sources: [{src: url}], - controls: false, - licenseUrl: 'https://license.vod2.myqcloud.com/license/v2/1328581896_1/v_cube.license' - } - ) - player.on('pause', () => { - setState({playing: false, end: false, error: false}) - }) - player.on('playing', () => { - setState({playing: true, end: false, error: false}) - }) - player.on('ended', () => { - setState({end: true, playing: false, error: false}) - }) - player.on('error', () => { - setState({end: false, playing: false, error: true}) - }) - if (!tcPlayer) { - setTcPlayer(() => player) - } - if(prevUrl == url){ + console.log('play', url, currentTime) + if (!tcPlayer) return; + const player = tcPlayer + if (prevUrl == url) { player.currentTime(0) - }else{ + } else { player.src(url) } player.play() @@ -92,9 +106,6 @@ export const Player = React.forwardRef((props, ref) => { } }) - return
- + return
}) \ No newline at end of file diff --git a/src/pages/library/components/search-form.tsx b/src/pages/library/components/search-form.tsx index 5835daf..0491ff2 100644 --- a/src/pages/library/components/search-form.tsx +++ b/src/pages/library/components/search-form.tsx @@ -3,44 +3,33 @@ import {useSetState} from "ahooks"; import {PlayCircleOutlined} from "@ant-design/icons"; import {SearchListTimes} from "@/pages/news/components/news-source.ts"; -type SearchParams = { - keywords?: string; - date?: string; -} - type Props = { - onSearch?: (params: SearchParams) => Promise; + onSearch?: (params: VideoSearchParams) => void; onBtnStartClick?: () => Promise; + loading?:boolean; } -export default function SearchForm({onSearch, onBtnStartClick}: Props) { +export default function SearchForm({onSearch, onBtnStartClick,loading}: Props) { const [state, setState] = useSetState<{ - timeRange: string; - keywords: string; - searching: boolean; - time: number; - }>({ - keywords: "", searching: false, timeRange: "", time: 0 - }) - const onFinish = (values: any) => { - setState({searching: true}) + pushing?: boolean; + }>({}) + const onFinish = (values) => { onSearch?.({ - keywords: values.keywords, - date: values.timeRange.join('-'), - }).finally(() => { - setState({searching: false}) + ...values, + pagination: {page: 1, limit: 10} }) + //console.log(values) } return (
-
- - + className={""} layout="inline" onFinish={onFinish} initialValues={{title:'',time_flag:0}}> + + - +