Browse Source

萤石播放器 99.9%

release_0.0.2
巴林闲侠 3 years ago
parent
commit
b0d21b367c
  1. 22
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperation.jsx
  2. 31
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationHistroyProcess.jsx
  3. 14
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationVoice.jsx
  4. 128
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoPlay.jsx
  5. 4
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoPlayModal.jsx
  6. 12
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/voiceHeader.jsx
  7. 4
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx

22
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperation.jsx

@ -20,8 +20,10 @@ const VideoOperation = ({
resolution, setResolution, resolution, setResolution,
histroyTime, setHistroyTime, histroyTime, setHistroyTime,
histroyBegain, histroyBegain,
play, pause, isPlaying, play, pause, closeSound, openSound,
videoObj isPlaying,
videoObj,
setYingshiPrepare, yingshiPrepareRef
}) => { }) => {
const [showTimeSelect, setShowTimeSelect] = useState(false) const [showTimeSelect, setShowTimeSelect] = useState(false)
@ -32,6 +34,13 @@ const VideoOperation = ({
} }
const changeResolution = () => { const changeResolution = () => {
if (yingshiPrepareRef.current) {
return
}
if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = 'yingshi'
setYingshiPrepare('play')
}
setResolution(resolution == 'sd' ? 'hd' : 'sd') setResolution(resolution == 'sd' ? 'hd' : 'sd')
} }
@ -73,17 +82,23 @@ const VideoOperation = ({
<> <>
<div style={{ display: 'flex', alignItems: 'center' }}> <div style={{ display: 'flex', alignItems: 'center' }}>
{ {
videoObj.type != 'yingshi' ?
isPlaying ? isPlaying ?
<IconPause style={{ cursor: 'pointer' }} onClick={pause} /> <IconPause style={{ cursor: 'pointer' }} onClick={pause} />
: <IconPlay style={{ cursor: 'pointer' }} onClick={play} /> : <IconPlay style={{ cursor: 'pointer' }} onClick={play} />
: ''
} }
<span style={{ marginLeft: 12 }}> <span style={{ marginLeft: 12 }}>
{histroyTime.length ? `${moment(histroyTime[0]).format(timeFormat)} / ${moment(histroyTime[1]).format(timeFormat)}` : ''} {histroyTime.length ? `${moment(histroyTime[0]).format(timeFormat)} / ${moment(histroyTime[1]).format(timeFormat)}` : ''}
</span> </span>
</div> </div>
<div style={{ display: 'flex', alignItems: 'center' }}> <div style={{ display: 'flex', alignItems: 'center' }}>
<VideoOperationVoice voiceDisY={voiceDisY} setVoiceDisY={setVoiceDisY} /> <VideoOperationVoice voiceDisY={voiceDisY} setVoiceDisY={setVoiceDisY} videoObj={videoObj} closeSound={closeSound} openSound={openSound} />
{
videoObj.type != 'yingshi' ?
<VideoOperationSpeed butStyle={butStyle} /> <VideoOperationSpeed butStyle={butStyle} />
: ''
}
<div style={butStyle} onClick={() => { <div style={butStyle} onClick={() => {
setShowTimeSelect(!showTimeSelect) setShowTimeSelect(!showTimeSelect)
}}>时间设置</div> }}>时间设置</div>
@ -95,6 +110,7 @@ const VideoOperation = ({
{ {
operationState ? operationState ?
operation.map(p => { operation.map(p => {
if (p.hide) return null;
return <img return <img
src={`/assets/images/background/video-icon-${p.key}-${operationState[p.key].select ? 'select' : 'unselect'}.png`} src={`/assets/images/background/video-icon-${p.key}-${operationState[p.key].select ? 'select' : 'unselect'}.png`}
height={18} height={18}

31
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationHistroyProcess.jsx

@ -8,7 +8,11 @@ const timeFormat = 'MM-DD HH:mm:ss'
const videoOperationHistroyProcess = ({ processDisX, setProcessDisX, histroyTime, isAdjustProcess, setIsAdjustProcess, }) => { const videoOperationHistroyProcess = ({ processDisX, setProcessDisX, histroyTime, isAdjustProcess, setIsAdjustProcess, }) => {
const [timeRangeS, setTimeRangeS] = useState(0) const [timeRangeS, setTimeRangeS] = useState(0)
const [processDisXRatio, setProcessDisXRatio] = useState(0)
const pointParentWidthRef = useRef(null)
useEffect(() => {
pointParentWidthRef.current = document.getElementById('process_point').parentElement.offsetWidth
}, [])
useEffect(() => { useEffect(() => {
if (histroyTime.length) { if (histroyTime.length) {
@ -57,24 +61,37 @@ const videoOperationHistroyProcess = ({ processDisX, setProcessDisX, histroyTime
x = parentWidth x = parentWidth
} }
setProcessDisX(x) setProcessDisX(x)
setProcessDisXRatio(x / parentWidth) point.style.left = x - 4.5 + 'px';
point.style.left = x + 'px';
prev = Date.now(); prev = Date.now();
} }
}; };
}} }}
> >
{/* <div <div
className={"video_process_time"} className={"video_process_time"}
style={{ style={{
backgroundColor: '#0000007F', position: 'absolute', backgroundColor: '#0000007F', position: 'absolute',
top: -32, height: 24, lineHeight: '24px', textAlign: 'center', width: 94, left: -38 top: -32, height: 24, lineHeight: '24px', textAlign: 'center', width: 94,
left:
processDisX < 38 ?
-processDisX :
processDisX + 38 > pointParentWidthRef.current - 4.5 ?
-38 - (38 - (pointParentWidthRef.current - 4.5 - processDisX)) :
-38
,
}}> }}>
{moment(histroyTime[0]).add(timeRangeS * processDisXRatio, 'seconds').format(timeFormat)} {
</div> */} moment(histroyTime[0])
.add(
timeRangeS * (processDisX / pointParentWidthRef.current),
'second'
)
.format(timeFormat)
}
</div> </div>
</div> </div>
</div> </div>
</div >
) )
} }

14
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationVoice.jsx

@ -1,12 +1,15 @@
import React, { useState, useEffect, useRef } from "react"; import React, { useState, useEffect, useRef } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { IconVolume2, } from '@douyinfe/semi-icons'; import { IconVolume2, IconVolumnSilent } from '@douyinfe/semi-icons';
import './videoPlay.less'; import './videoPlay.less';
const VideoOperationVoice = ({ voiceDisY, setVoiceDisY }) => { const VideoOperationVoice = ({ voiceDisY, setVoiceDisY, videoObj, closeSound, openSound }) => {
return ( return (
<div className="video_voice_but" style={{ display: 'flex', alignItems: 'center', position: 'relative', height: '100%', }}> <div className="video_voice_but" style={{ display: 'flex', alignItems: 'center', position: 'relative', height: '100%', }}>
{
videoObj.type == 'yingshi' ?
'' :
<div className="video_voice_options"> <div className="video_voice_options">
<div style={{ <div style={{
position: 'absolute', top: -100 - 32 - 16, backgroundColor: '#00000099', width: 32, position: 'absolute', top: -100 - 32 - 16, backgroundColor: '#00000099', width: 32,
@ -59,7 +62,12 @@ const VideoOperationVoice = ({ voiceDisY, setVoiceDisY }) => {
</div> </div>
</div> </div>
</div> </div>
<IconVolume2 style={{ cursor: 'pointer' }} /> }
{
voiceDisY ?
<IconVolume2 style={{ cursor: 'pointer' }} onClick={closeSound} />
: <IconVolumnSilent style={{ cursor: 'pointer' }} onClick={openSound} />
}
</div> </div>
) )
} }

128
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoPlay.jsx

@ -8,18 +8,23 @@ import './videoPlay.less';
const timeFormat = 'YYYY-MM-DD HH:mm:ss' const timeFormat = 'YYYY-MM-DD HH:mm:ss'
const yingshiUrl = 'https://open.ys7.com/ezopen/h5/iframe' const yingshiUrl = 'https://open.ys7.com/ezopen/h5/iframe'
const yingshiCloseSoundKey = 'closeSound'
const yingshiOpenSoundKey = 'openSound'
const VideoPlay = ({ const VideoPlay = ({
height, width, containerId = 'myPlayer', height, width, containerId = 'myPlayer',
// playUrl, // playUrl,
name, name,
videoObj = { videoObj = {
type: 'yingshi', type: 'yingshi',
audio: true, audio: false,
yingshiToken: 'at.3j6eyqbn0g5xvcut73v0rzdu1nh0gnxx-4ua03m82o9-12u1t9g-rtzndpyds', serialNo: 'G75922040', //
playUrlSd: 'ezopen://open.ys7.com/G75922040/1.live', channelNo: 1, //
yingshiToken: 'at.3j6eyqbn0g5xvcut73v0rzdu1nh0gnxx-4ua03m82o9-12u1t9g-rtzndpyds', //
playUrlSd: 'ezopen://open.ys7.com/G75922040/1.live', //
// playUrl: 'ws://221.230.55.27:8081/jessica/34020000001110000077/34020000001310000003', // playUrl: 'ws://221.230.55.27:8081/jessica/34020000001110000077/34020000001310000003',
playUrlHd: 'ezopen://open.ys7.com/G75922040/1.hd.live', playUrlHd: 'ezopen://open.ys7.com/G75922040/1.hd.live',
replayUrl: 'ezopen://open.ys7.com/G75922040/1.rec', // replayUrl: 'ezopen://open.ys7.com/G75922040/1.rec',
}, },
}) => { }) => {
const [jessibuca, setjessibuca] = useState(null) const [jessibuca, setjessibuca] = useState(null)
@ -32,10 +37,18 @@ const VideoPlay = ({
const [histroyBegain, setHistroyBegain] = useState() const [histroyBegain, setHistroyBegain] = useState()
const [resolution, setResolution] = useState('sd') // sd hd const [resolution, setResolution] = useState('sd') // sd hd
// ifream
const [yingshiPrepare, setYingshiPrepare] = useState('')
const operationRef = useRef(null) const operationRef = useRef(null)
const processChangeTimeoutRef = useRef(null) const processChangeTimeoutRef = useRef(null)
// ifream
const yingshiPrepareRef = useRef(null)
const changeSelectState = (key) => { const changeSelectState = (key) => {
if (videoObj.type == 'yingshi' && yingshiPrepareRef.current) {
return
}
const nextOperationState = JSON.parse(JSON.stringify(operationRef.current)) const nextOperationState = JSON.parse(JSON.stringify(operationRef.current))
if (key == 'histroy' && nextOperationState.histroy.select) { if (key == 'histroy' && nextOperationState.histroy.select) {
// //
@ -71,7 +84,9 @@ const VideoPlay = ({
}, { }, {
key: 'fullScreen', key: 'fullScreen',
click: () => { click: () => {
if (yingshiPrepareRef.current) {
return
}
changeSelectState('fullScreen') changeSelectState('fullScreen')
let player = document.getElementById('vcmp_videoplay') let player = document.getElementById('vcmp_videoplay')
if (screenfull.isEnabled) { if (screenfull.isEnabled) {
@ -80,14 +95,21 @@ const VideoPlay = ({
} }
}, { }, {
key: 'histroy', key: 'histroy',
hide: !Boolean(videoObj.replayUrl),
click: () => { click: () => {
changeSelectState('histroy') changeSelectState('histroy')
yingshiPrepareRef.current = 'play'
setYingshiPrepare('play')
} }
},] },]
useEffect(() => { useEffect(() => {
create() if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = 'play'
setYingshiPrepare('play')
} else {
createJessibuca()
}
let nextOperationState = {} let nextOperationState = {}
for (let p of operation) { for (let p of operation) {
nextOperationState[p.key] = { nextOperationState[p.key] = {
@ -108,29 +130,42 @@ const VideoPlay = ({
}); });
// ifream // ifream
// const listenYingshiMessage = async (e) => { const listenYingshiMessage = async (e) => {
// const { data, origin } = e const { data, origin } = e
// console.log(e); console.log(e);
// if (origin !== 'https://open.ys7.com') return if (origin !== 'https://open.ys7.com') return
// if (data.type == 'stop' && data.code == 1) { if (data.type == "handleSuccess") {
// setIsPlaying(false) if (yingshiPrepareRef.current == 'play') {
// } setIsPlaying(true)
// if (data.type == 'stop' && data.code == 1) { }
// setIsPlaying(false) } else if (data.type == yingshiOpenSoundKey && data.code == 0) {
// } if (yingshiPrepareRef.current == yingshiOpenSoundKey) {
// } setVoiceDisY(30)
// if (videoObj.type == 'yingshi') { }
// window.addEventListener('message', listenYingshiMessage); } if (data.type == yingshiCloseSoundKey && data.code == 0) {
// } if (yingshiPrepareRef.current == yingshiCloseSoundKey) {
// return () => { setVoiceDisY(0)
// window.removeEventListener('message', listenYingshiMessage); }
// } }
yingshiPrepareRef.current = null
setYingshiPrepare(null)
}
if (videoObj.type == 'yingshi') {
window.addEventListener('message', listenYingshiMessage);
}
return () => {
window.removeEventListener('message', listenYingshiMessage);
}
}, []) }, [])
useEffect(() => { useEffect(() => {
if (histroyTime.length) { if (histroyTime.length) {
setHistroyBegain(histroyTime[0]) setHistroyBegain(histroyTime[0])
document.getElementById('process_point').style.left = 0 + 'px'; // document.getElementById('process_point').style.left = 0 + 'px'; //
if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = 'play'
setYingshiPrepare('play')
}
} else { } else {
setHistroyBegain(null) setHistroyBegain(null)
} }
@ -138,6 +173,7 @@ const VideoPlay = ({
useEffect(() => { useEffect(() => {
if (operationState && operationState.histroy.select) { if (operationState && operationState.histroy.select) {
if (isAdjustProcess) { if (isAdjustProcess) {
//
if (processChangeTimeoutRef.current) { if (processChangeTimeoutRef.current) {
clearTimeout(processChangeTimeoutRef.current) clearTimeout(processChangeTimeoutRef.current)
} }
@ -150,14 +186,19 @@ const VideoPlay = ({
) )
.format(timeFormat) .format(timeFormat)
) )
if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = 'play'
setYingshiPrepare('play')
}
}, 300) }, 300)
} else { } else {
document.getElementById('process_point').style.left = processDisX + 'px' //
document.getElementById('process_point').style.left = processDisX - 4.5 + 'px'
} }
} }
}, [processDisX]) }, [processDisX])
const create = () => { const createJessibuca = () => {
if (videoObj.type != 'yingshi') { if (videoObj.type != 'yingshi') {
let $container = document.getElementById('container'); let $container = document.getElementById('container');
const jessibuca = new window.Jessibuca({ const jessibuca = new window.Jessibuca({
@ -183,9 +224,8 @@ const VideoPlay = ({
} }
const yingshiOperation = (operation) => { const yingshiOperation = (operation) => {
let a = document.getElementById(containerId).contentWindow.postMessage(operation, yingshiUrl) document.getElementById(containerId).contentWindow.postMessage(operation, yingshiUrl)
console.log(a); // setIsPlaying(operation == 'play')
setIsPlaying(operation == 'play')
} }
const play = () => { const play = () => {
@ -199,13 +239,29 @@ const VideoPlay = ({
const pause = () => { const pause = () => {
if (videoObj.type == 'yingshi') { if (videoObj.type == 'yingshi') {
yingshiOperation('stop') // yingshiOperation('stop')
} else if (jessibuca) { } else if (jessibuca) {
jessibuca.pause(); jessibuca.pause();
setIsPlaying(false) setIsPlaying(false)
} }
} }
const closeSound = () => {
if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = yingshiCloseSoundKey
setYingshiPrepare(yingshiCloseSoundKey)
yingshiOperation(yingshiCloseSoundKey)
}
}
const openSound = () => {
if (videoObj.type == 'yingshi') {
yingshiPrepareRef.current = yingshiOpenSoundKey
setYingshiPrepare(yingshiOpenSoundKey)
yingshiOperation(yingshiOpenSoundKey)
}
}
return ( return (
<> <>
<div className="vcmp_videoplay" style={{ height: height || '100%', width: width || '100%' }}> <div className="vcmp_videoplay" style={{ height: height || '100%', width: width || '100%' }}>
@ -215,7 +271,10 @@ const VideoPlay = ({
operationState={operationState} changeSelectState={changeSelectState} operationState={operationState} changeSelectState={changeSelectState}
histroyTime={histroyTime} histroyTime={histroyTime}
setoperationState={setoperationState} name={name} setoperationState={setoperationState} name={name}
showTime={histroyBegain} showTime={
videoObj.type == 'yingshi' && yingshiPrepare == 'play' ?
null : (histroyBegain || moment())
}
setProcessDisX={setProcessDisX} setProcessDisX={setProcessDisX}
/> />
{/* 视频内容 */} {/* 视频内容 */}
@ -225,7 +284,7 @@ const VideoPlay = ({
frameBorder="0" frameBorder="0"
id={containerId} id={containerId}
src={ src={
`${yingshiUrl}?audio=${videoObj.audio ? '1' : '0'}&url=${operationState && operationState.histroy.select && histroyBegain ? `${videoObj.replayUrl}?begin=${moment(histroyBegain).format("YYYYMMDDHHmmss")}&end=${moment(histroyTime[1]).format("YYYYMMDDHHmmss")}` : resolution == 'sd' ? videoObj.playUrlSd : videoObj.playUrlHd}&autoplay=${'1'}&accessToken=${videoObj.yingshiToken}` `${yingshiUrl}?audio=${videoObj.audio && operationState && !operationState.histroy.select ? '1' : '0'}&url=${operationState && operationState.histroy.select && histroyBegain ? `${videoObj.replayUrl}?begin=${moment(histroyBegain).format("YYYYMMDDHHmmss")}&end=${moment(histroyTime[1]).format("YYYYMMDDHHmmss")}` : resolution == 'sd' ? videoObj.playUrlSd : videoObj.playUrlHd}&autoplay=${'1'}&accessToken=${videoObj.yingshiToken}`
} }
// https://open.ys7.com/doc/zh/book/index/live_proto.html // https://open.ys7.com/doc/zh/book/index/live_proto.html
// {width: 400px;height: 300px;} // {width: 400px;height: 300px;}
@ -252,10 +311,11 @@ const VideoPlay = ({
resolution={resolution} setResolution={setResolution} resolution={resolution} setResolution={setResolution}
histroyTime={histroyTime} setHistroyTime={setHistroyTime} histroyTime={histroyTime} setHistroyTime={setHistroyTime}
histroyBegain={histroyBegain} histroyBegain={histroyBegain}
play={play} play={play} pause={pause} closeSound={closeSound} openSound={openSound}
pause={pause}
isPlaying={isPlaying} isPlaying={isPlaying}
videoObj={videoObj} videoObj={videoObj}
setYingshiPrepare={setYingshiPrepare}
yingshiPrepareRef={yingshiPrepareRef}
/> />
</div> </div>

4
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoPlayModal.jsx

@ -5,7 +5,7 @@ import { Button, Modal, } from "@douyinfe/semi-ui";
import VideoPlay from './videoPlay.jsx' import VideoPlay from './videoPlay.jsx'
import './videoPlayModal.less'; import './videoPlayModal.less';
const VideoPlayModal = ({ visible, close }) => { const VideoPlayModal = ({ visible, close, videoObj, name }) => {
return ( return (
<Modal <Modal
@ -18,7 +18,7 @@ const VideoPlayModal = ({ visible, close }) => {
onCancel={() => { close() }} onCancel={() => { close() }}
className="videoModal" className="videoModal"
> >
<VideoPlay height={460} /> <VideoPlay height={460} videoObj={videoObj} name={name} />
</Modal> </Modal>
) )
} }

12
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/voiceHeader.jsx

@ -11,9 +11,14 @@ const timeFormat = 'YYYY-MM-DD HH:mm:ss'
const VideoHeader = ({ operationState, changeSelectState, setProcessDisX, name, showTime, histroyTime }) => { const VideoHeader = ({ operationState, changeSelectState, setProcessDisX, name, showTime, histroyTime }) => {
const time = useRef(moment(showTime || undefined)) const time = useRef(moment(showTime || undefined))
const upTimeInterval = useRef(null) const upTimeInterval = useRef(null)
const [showTime_, setShowTime] = useState(time.current.format(timeFormat)) const [showTime_, setShowTime] = useState(' ')
const updateTime = () => { const updateTime = () => {
if (!showTime) {
setShowTime('')
clearInterval(upTimeInterval.current)
return
}
time.current = moment(showTime || undefined) time.current = moment(showTime || undefined)
if (upTimeInterval.current) { if (upTimeInterval.current) {
clearInterval(upTimeInterval.current) clearInterval(upTimeInterval.current)
@ -22,6 +27,9 @@ const VideoHeader = ({ operationState, changeSelectState, setProcessDisX, name,
time.current.add(1, 's') time.current.add(1, 's')
if (operationState && operationState.histroy.select) { if (operationState && operationState.histroy.select) {
// setProcessDisX(Math.random() * 300 + 100) // setProcessDisX(Math.random() * 300 + 100)
if (time.current.isSameOrAfter(histroyTime[1])) {
clearInterval(upTimeInterval.current)
}
setProcessDisX( setProcessDisX(
time.current.diff(moment(histroyTime[0]), 'seconds') / moment(histroyTime[1]).diff(moment(histroyTime[0]), 'seconds') * document.getElementById('process_point').parentElement.offsetWidth time.current.diff(moment(histroyTime[0]), 'seconds') / moment(histroyTime[1]).diff(moment(histroyTime[0]), 'seconds') * document.getElementById('process_point').parentElement.offsetWidth
) )
@ -70,7 +78,7 @@ const VideoHeader = ({ operationState, changeSelectState, setProcessDisX, name,
</Col> </Col>
<Col span={15} style={{}}> <Col span={15} style={{}}>
<div style={{ paddingRight: 12 }}> <div style={{ paddingRight: 12 }}>
<TextScroll content={['asdadasdasdasdasdasd', '123123']} duration={6} /> <TextScroll content={[]} duration={6} />
</div> </div>
</Col> </Col>
</Row> </Row>

4
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -153,8 +153,8 @@ const Root = props => {
// IOT system cross // IOT system cross
window.addEventListener('message', async function (e) { // message window.addEventListener('message', async function (e) { // message
const { data } = e const { data, origin } = e
console.log(e); if (origin == 'https://open.ys7.com') return
if (data && data.action) { if (data && data.action) {
if (data.action == 'initUser') { if (data.action == 'initUser') {
await store.dispatch(actions.auth.initAuth(data.user)) await store.dispatch(actions.auth.initAuth(data.user))

Loading…
Cancel
Save