当前位置:   article > 正文

videojs多个视频一起播放暂停_videojs 视频选集 一起的

videojs 视频选集 一起的

需求

多个视频要用同一个进度条控制播放暂停
在这里插入图片描述

进度条

这个可以用antd的Slider组件

<Slider
	marks={marks}
	max={maxTime}
	defaultValue={timeValue}
	value={timeValue}
	tooltipVisible={false}
	onAfterChange={(v) => handleAfterChange(v)}
	onChange={(value) => handleSliderValue(value)}
/>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

视频播放videojs

<video
	id={!nickname ? '' : `play${id}`}
	muted="muted"
	className="video-js vjs-fluid"
	// controls
	preload="auto"
	// poster="//vjs.zencdn.net/v/oceans.png"
	data-setup="{}"
>
	<source src={mediaUrl} type={sourceType} />
</video>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

初始化多个videojs

// 初始化videoJs
	const handleInitVideo = () => {
		// debugger
		// console.log({masterList})
		videoList.map(v => {
			const {id, nickname } = v
			// console.log(document.getElementById(`play${id}`))
				if (document.getElementById(`play${id}`) && !current[`play${id}`] && nickname) {
						current[`play${id}`] = videoJs(`play${id}`, { fluid: true }, function() {
											console.log(`1111play${id}`);
											// current[`play${id}`].play();
									});
									current[`play${id}`].src([{src:v.mediaUrl, type:v.sourceType}]) 
							}
							return
			// }
		})
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

多个视频一起播放暂停

// 遍历每个video
	const handleEveryVideo = (list, fun, time) => {
		for (let i in list) {
			if (i !== 'timer' && list[i]) {
				// console.log('list[i]', fun,i, list[i])
				switch (fun) {
					case 'play': // 播放
						list[i].play();
						break;
					case 'pause': // 暂停
						list[i].pause();
						break; // 设置时间点
					case 'currentTime':
						list[i].currentTime(time);
						break;
					case 'dispose': // 销毁
						list[i].dispose();
						break;

					default:
						break;
				}
			}
		}
	}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

部分代码

VideoLeft组件

import React, { useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
import Slider from 'react-slick';
import videoJs from 'video.js';
// import moment from 'moment';
import { Slider as Sli } from 'antd';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
import arr from '../../images/arr-right.svg';
import qh from '../../images/qh.svg';
import play from '../../images/play.svg';
import pause from '../../images/pause.svg';
import kj from '../../images/kj.svg';
import kt from '../../images/kt.svg';
// import CandidateVideo from './candidateVideo';

import './index.scss';



// const startTime = 1581926464;
// const endTime = 1582926501;

// const maxTime = endTime - startTime;
// const maxTime = 46000;


const VideoLeft = forwardRef(({videoList = [], masterList=[], currentVideoInfo,
	setCurrentVideoInfo, handleChangeCandidateVideo, setCurrentMasterInfo,
	currentMasteroInfo, handleChangeMasterVideo, formatDuring,
	timeValue,setTimeValue, current, setIsPlay, isPlay, maxTime
}, ref) => {
	// const [ isPlay, setIsPlay ] = useState(false);
	const [ slideList, setSlideList ] = useState([]);

	const slideRef = useRef();
	// let { current } = useRef({ timer: '' });
	// let masterVideo = useRef('');
	// let videojs = useRef('');
	const marks = {
		0: formatDuring(timeValue)
		// maxTime: formatDuring(maxTime),
	};
	marks[maxTime] = formatDuring(maxTime);


	const handleSlideList = info => {
		const slideList = videoList.filter(i => i.id !== info.id)
	// console.log({slideList})
		setSlideList(slideList)
		return 'ok'
	}
	// useEffect(() => {
	// 	if (allVideoList.length && allVideoList[0].startTime) handleObtainTime()
	// }, [allVideoList])
	
	useEffect(() => {
		// console.log('slideList1')
		if(videoList.length) handleSlideList(currentVideoInfo)
	},[videoList, currentVideoInfo])

	// 遍历每个video
	const handleEveryVideo = (list, fun, time) => {
		for (let i in list) {
			if (i !== 'timer' && list[i]) {
				// console.log('list[i]', fun,i, list[i])
				switch (fun) {
					case 'play': // 播放
						list[i].play();
						break;
					case 'pause': // 暂停
						list[i].pause();
						break; // 设置时间点
					case 'currentTime':
						list[i].currentTime(time);
						break;
					case 'dispose': // 销毁
						list[i].dispose();
						break;

					default:
						break;
				}
			}
		}
	}
	// 可以让父组件调用子组件的方法
	useImperativeHandle(ref, () => ({
	// 点击左右切换候视频
	hanldeChangeListVideo (video, list, index, type) {
		// console.log({type})
		let v = JSON.parse(JSON.stringify(video));
		// if (index > -1) {
			setIsPlay(false);
			// console.log('index', list, currentVideoInfo)
			if (type === '1') { // 候选人
				current[`play${list[index].id}`].src([{src:currentVideoInfo.mediaUrl, type:currentVideoInfo.sourceType}]) // 设置当前选择的候选人src
				current[`play${currentVideoInfo.id}`].src([{src:v.mediaUrl, type:v.sourceType}]) // 设置大框的候选人src
				list[index].nickname = currentVideoInfo.nickname
				list[index].mediaUrl = currentVideoInfo.mediaUrl
				list[index].sourceType = currentVideoInfo.sourceType
				setCurrentVideoInfo({id:currentVideoInfo.id,nickname:v.nickname, mediaUrl:v.mediaUrl,sourceType:v.sourceType})
			} else { // 面试官
				// current[`play${list[index].id}`].src([{src:currentMasteroInfo.mediaUrl, type:currentMasteroInfo.sourceType}]) // 设置当前选择的面试官src
				current[`play${currentMasteroInfo.id}`].src([{src:v.mediaUrl, type:v.sourceType}]) // 设置大框的面试官src
				// list[index].nickname = currentMasteroInfo.nickname
				// list[index].mediaUrl = currentMasteroInfo.mediaUrl
				// list[index].sourceType = currentMasteroInfo.sourceType
				setCurrentMasterInfo({id:currentMasteroInfo.id,nickname:v.nickname, mediaUrl:v.mediaUrl,sourceType:v.sourceType})
			}
			const second = parseInt(timeValue / 1000);
			// handleInitVideo()
			handleEveryVideo(current, 'currentTime', second);// 给视频指定播放时间点
			// console.log('slideList',slideList)

		// }
		// setIsPlay(true);
	}
  }));

	// 点击切换候选人视频
	const hanldeChangeVideo = async video => {
		// handleEveryVideo(current, 'dispose');// 给视频指定播放时间点
		let v = JSON.parse(JSON.stringify(video));
		// let c = JSON.parse(JSON.stringify(currentVideoInfo));
		const index = videoList.map(item => item.id).indexOf(video.id)
		if (index > -1) {
			// videoList[index] = currentVideoInfo
			setIsPlay(false);
			// setSlideList([...videoList])
			current[`play${videoList[index].id}`].src([{src:currentVideoInfo.mediaUrl, type:currentVideoInfo.sourceType}]) // 设置当前选择的候选人src
			current[`play${currentVideoInfo.id}`].src([{src:v.mediaUrl, type:v.sourceType}]) // 设置大框的候选人src
			videoList[index].nickname = currentVideoInfo.nickname
			videoList[index].mediaUrl = currentVideoInfo.mediaUrl
			videoList[index].sourceType = currentVideoInfo.sourceType
			// console.log('index', v, video, videoList[index], c,currentVideoInfo)
	
			setCurrentVideoInfo({id:currentVideoInfo.id,nickname:v.nickname, mediaUrl:v.mediaUrl,sourceType:v.sourceType})
			const second = parseInt(timeValue / 1000);
			// handleInitVideo()
			handleEveryVideo(current, 'currentTime', second);// 给视频指定播放时间点
			// console.log('slideList',slideList)

		}
		// setIsPlay(true);
	}


	// 点击滑块到某个点之后
	const handleAfterChange = (v) => {
		// console.log({v});
		// clearInterval(timer);
		setTimeValue(v);
		const second = parseInt(v / 1000);
		// current.videojs.currentTime(second); // 给视频指定播放时间点
		// current.masterVideo.currentTime(second);
		handleEveryVideo(current, 'currentTime', second);
		// console.log({current})
	};
	// 滑块的变化
	const handleSliderValue = (v) => {
		// clearInterval(timer);
		setTimeValue(v);
	};
	// const time = formatDuring(maxTime)
	// console.log({time});
	// 开始暂停
	const handlePlay = () => {
		setIsPlay(!isPlay);
	};
	// 快进10秒
	const handleFastForward = () => {
		timeValue = timeValue + 10000;
		if (timeValue <= maxTime) {
			setTimeValue(timeValue);
			const second = parseInt(timeValue / 1000);
			// current.videojs.currentTime(second); // 给视频指定播放时间点
			// current.masterVideo.currentTime(second); // 给视频指定播放时间点
			handleEveryVideo(current, 'currentTime', second);
		} else {
			setTimeValue(maxTime);
			const second = parseInt(maxTime / 1000);
			handleEveryVideo(current, 'currentTime', second);
			// current.videojs.currentTime(second); // 给视频指定播放时间点
			// current.masterVideo.currentTime(second); // 给视频指定播放时间点
		}
	};
	// 快退10秒
	const handleFastBack = () => {
		timeValue = timeValue - 10000;
		if (timeValue > 0) {
			setTimeValue(timeValue);
			const second = parseInt(timeValue / 1000);
			handleEveryVideo(current, 'currentTime', second);
			// current.videojs.currentTime(second); // 给视频指定播放时间点
			// current.masterVideo.currentTime(second); // 给视频指定播放时间点
		} else {
			setTimeValue(0);
			handleEveryVideo(current, 'currentTime', 0);
			// current.videojs.currentTime(0); // 给视频指定播放时间点
			// current.masterVideo.currentTime(0); // 给视频指定播放时间点
		}
		// setTimeValue(timeValue);
	};

	// 初始化videoJs
	const handleInitVideo = () => {
		// debugger
		// console.log({masterList})
		videoList.map(v => {
			const {id, nickname } = v
			// console.log(document.getElementById(`play${id}`))
				if (document.getElementById(`play${id}`) && !current[`play${id}`] && nickname) {
						current[`play${id}`] = videoJs(`play${id}`, { fluid: true }, function() {
											console.log(`1111play${id}`);
											// current[`play${id}`].play();
									});
									current[`play${id}`].src([{src:v.mediaUrl, type:v.sourceType}]) 
							}
							return
			// }
		})
	}
	// 初始化面试官videoJs
	const handleInitMasterVideo = () => {
		// debugger
		// console.log({masterList})
		masterList.map(v => {
			const {id, nickname } = v
			// console.log(document.getElementById(`play${id}`))
				if (document.getElementById(`play${id}`) && !current[`play${id}`] && nickname) {
						current[`play${id}`] = videoJs(`play${id}`, { fluid: true }, function() {
											console.log(`222play${id}`);
											// current[`play${id}`].play();
									});
									current[`play${id}`].src([{src:v.mediaUrl, type:v.sourceType}]) 
							}
							return
			// }
		})
	}
	useEffect(
		() => {
			clearInterval(current.timer);
			// console.log({isPlay});
			if (isPlay) {
				current.timer = setInterval(() => {
					timeValue = timeValue + 1000;
					setTimeValue(timeValue);
					if (timeValue >= maxTime) {
						setTimeValue(maxTime);
						clearInterval(current.timer);
						setIsPlay(false);
					}
				}, 1000);
			}
		},
		[ current.timer, timeValue, isPlay ]
		);


	useEffect(
		() => {
			// if (document.getElementById(`play${currentMasteroInfo.id}`) && document.getElementById(`play${currentVideoInfo.id}`)) {
				current[`play${currentMasteroInfo.id}`] = videoJs(`play${currentMasteroInfo.id}`, { fluid: true }, function() {
					console.log('Good to go1!');
					// player.play();
					if (masterList.length) handleInitMasterVideo()
				});

				current[`play${currentVideoInfo.id}`] = videoJs(`play${currentVideoInfo.id}`, { fluid: true }, function() {
					console.log('Good to go!');
					// player.play();
					if (videoList.length) handleInitVideo()
					
				});
				// console.log({videoList})
				// handleInitVideo()
				if (isPlay) {
					handleEveryVideo(current, 'play');
				} else {
					handleEveryVideo(current, 'pause');
				}
				// current.videojs.on('play', function() {
				// 	console.log('开始/恢复播放');
				// });

				// current.videojs.on('ended', function() {
				// 	console.log('结束播放');
				// });
				// current.videojs.on('timeupdate', function() {
				// 	console.log('timeupdate');
				// });
			// }
		},
		[ isPlay, current, videoList, masterList]
	);
	const settings = {
		// focusOnSelect: true,
		infinite: true,
		slidesToShow: 3,
		slidesToScroll: 3,
		speed: 500
		// nextArrow:<Right />,
		// prevArrow:<Right />,
	};

	// console.log({current,slideList, videoList})
	return (
		<div className="video-container">
			<h4>面试回放</h4>
			<div className="video-master candidate-video">
				<div className="label-top">
					<span className="video-label master">面试官</span>
					<span className="video-time">{formatDuring(timeValue)}</span>
				</div>
				<div className="label-middle vertical-middle">
					<video
						id={`play${currentMasteroInfo.id}`}
						muted="muted"
						className="video-js vjs-fluid"
						width='320px'
						height='180px'
						// controls
						preload="auto"
						// poster="//vjs.zencdn.net/v/oceans.png"
						data-setup="{}"
					>
						<source src={currentMasteroInfo.mediaUrl} type={currentMasteroInfo.sourceType} />
					</video>
				</div>
				<div className="label-bottom">
					<span className="label-arrow" onClick={() => handleChangeMasterVideo('left')}>
						<img  className="rotate180" src={qh} alt="" />
					</span>
					<span className="master-name">{currentMasteroInfo.nickname}</span>
					<span className="label-arrow"  onClick={() => handleChangeMasterVideo('right')}>
						<img className="" src={qh} alt="" />
					</span>
				</div>
			</div>
			<div className="video-master candidate-video">
				<div className="label-top">
					<span className="video-label candidate">候选人</span>
					<span className="video-time">{formatDuring(timeValue)}</span>
				</div>
				<div className="label-middle vertical-middle">
					<video
						id={`play${currentVideoInfo.id}`}
						muted="muted"
						className="video-js vjs-fluid"
						// controls
						preload="auto"
						// poster="//vjs.zencdn.net/v/oceans.png"
						data-setup="{}"
					>
						<source src={currentVideoInfo.mediaUrl} type={currentVideoInfo.sourceType} />
					</video>
				</div>
				<div className="label-bottom">
					<span className="label-arrow" onClick={() => handleChangeCandidateVideo('left')}>
						<img className="rotate180" src={qh} alt="" />
					</span>
					<span className="master-name">{currentVideoInfo.nickname}</span>
					<span className="label-arrow" onClick={() => handleChangeCandidateVideo('right')}>
						<img className="" src={qh} alt="" />
					</span>
				</div>
			</div>
			{
				slideList.length > 3 ?
			<div className="candidate-bottom-slider">
				<img src={arr} alt="" className="left-arr rotate180" onClick={() => slideRef.current.slickPrev()} />
				<div className="candidate-slide">
					<Slider ref={slideRef} {...settings}>
						{slideList.map((video) => {
              const { id, nickname, mediaUrl, sourceType } = video;
							return (
								// <CandidateVideo key={video.id} video={video} current={current} isPlay={isPlay} />
								<div className={`${!nickname ? 'hide' : 'video-item '}`} key={id} onClick={() => hanldeChangeVideo(video)}>
									{/* <div className={`video-middle ${isLong ? 'video-vertical' : ''}`}> */}
									<div className="video-middle">
										<video
											id={!nickname ? '' : `play${id}`}
											muted="muted"
											className="video-js vjs-fluid"
											// controls
											preload="auto"
											// poster="//vjs.zencdn.net/v/oceans.png"
											data-setup="{}"
										>
											<source src={mediaUrl} type={sourceType} />
										</video>
									</div>
									<span className="candidate-name">{nickname}</span>
								</div>
							);
						})}
					</Slider>
				</div>
				<img src={arr} alt="" className="left-arr" onClick={() => slideRef.current.slickNext()} />
			</div> :
			<div className="candidate-bottom-slider">
			<div className="candidate-slide slide-three">
					{slideList.map((video) => {
						const { id, nickname,  mediaUrl, sourceType } = video;
						return (
							// <CandidateVideo key={video.id} video={video} current={current} isPlay={isPlay} />
							<div className={`${!nickname ? 'hide' : 'video-item '}`}key={id} onClick={() => hanldeChangeVideo(video)}>
								{/* <div className={`video-middle ${isLong ? 'video-vertical' : ''}`}> */}
								<div className="video-middle">
									<video
										id={`play${id}`}
										muted="muted"
										className="video-js vjs-fluid"
										// controls
										preload="auto"
										// poster="//vjs.zencdn.net/v/oceans.png"
										data-setup="{}"
									>
										<source src={mediaUrl} type={sourceType} />
									</video>
								</div>
								<span className="candidate-name">{nickname}</span>
							</div>
						);
					})}
			</div>
		</div>
			}
			<div className="slider-line">
				<Sli
					marks={marks}
					max={maxTime}
					defaultValue={timeValue}
					value={timeValue}
					tooltipVisible={false}
					onAfterChange={(v) => handleAfterChange(v)}
					onChange={(value) => handleSliderValue(value)}
				/>
			</div>
			<div className="play-pause">
				<span onClick={() => handleFastBack()}>
					<img src={kt} alt="" />
				</span>
				<span onClick={() => handlePlay()}>
					<img src={isPlay ? play : pause} alt="" />
				</span>
				<span onClick={() => handleFastForward()}>
					<img src={kj} alt="" />
				</span>
			</div>
		</div>
	);
});

export default VideoLeft;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457

App

import React, { useState, useEffect, useRef } from 'react';
import { message } from 'antd';
import './index.scss';
import VideoLeft from '../components/videoLeft';



// 获取url参数,调用方式:getQueryVariable('xxx')
const getQueryVariable = (variable) => {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
};

// 先查会议里面人的信息
const meetingInfo = {
  token: '111',
  userId: 'c_G111',
  roomId: 3009,
  startTime: '2021-02-04 16:38:00',
  endTime: '2021-02-04 17:38:00',
  userList: [
    {
      id: 'c_G12',
      phone: '13222222222',
      nickname: 'Alice',
      roomId: '2482',
          mediaUrl:'https://vjs.zencdn.net/v/oceans.mp4',
    startTime:1612495748,
    endTime:1612550188,
    sourceType:'video/mp4'
    },
    {
      id: 'c_G13',
      phone: '13222222223',
      nickname: 'Jane',
      roomId: '2482',
      mediaUrl:'https://vjs.zencdn.net/v/oceans.mp4',
    startTime:1612495748,
    endTime:1612550188,
    sourceType:'video/mp4'
    },
    {
      id: 'c_G14',
      phone: '13222222224',
      nickname: 'Jack',
      roomId: '2482',
      mediaUrl:'https://vjs.zencdn.net/v/oceans.mp4',
    startTime:1612495748,
    endTime:1612550188,
    sourceType:'video/mp4'
    },
    {
      id: 'c_G15',
      phone: '13222222225',
      nickname: 'UUUU',
      roomId: '2482',
      mediaUrl:'https://vjs.zencdn.net/v/oceans.mp4',
    startTime:1612495748,
    endTime:1612550188,
    sourceType:'video/mp4'
    },
    {
      id: 'c_G16',
      phone: '13222222226',
      nickname: 'OOOO',
      roomId: '2482',
      mediaUrl:'https://vjs.zencdn.net/v/oceans.mp4',
    startTime:1612495748,
    endTime:1612550188,
    sourceType:'video/mp4'
    },
  ],
  msg: ''
}
// 毫秒转化时分秒
const formatDuring = (mss) => {
  // var days = parseInt(mss / (1000 * 60 * 60 * 24));
  let hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  if (hours < 10) {
    hours = `0${hours}`;
  }
  let minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  if (minutes < 10) {
    minutes = `0${minutes}`;
  }
  let seconds = parseInt((mss % (1000 * 60)) / 1000);
  if (seconds < 10) {
    seconds = `0${seconds}`;
  }
  return `${hours}:${minutes}:${seconds}`;
};

const App = props => {
  //  console.log({props})
  const [currentVideoInfo, setCurrentVideoInfo] = useState({});
  const [currentMasteroInfo, setCurrentMasterInfo] = useState({});
  // const [ mediaUrl, setMediaUrl ] = useState([]); // 视频的url
  const [timeValue, setTimeValue] = useState(0); // 视频播放时间
  const [isPlay, setIsPlay] = useState(false); // 是否播放
  const [videoList, setVideoList] = useState([]);
  const [copyVideoList, setCopyVideoList] = useState([]);
  const [videoStartTime, setVideoStartTime] = useState(0); // 最长的视频开始时间戳
  // const [meetingInfo, setMeetingInfo] = useState(meetinginfo);
  const [maxTime, setMaxTime] = useState(0);
  let { current } = useRef({ timer: '' });
  const childMethodRef = useRef();
  //   
  const handleMeetingRoom = async () => {
    handleMeeting(meetingInfo)
      handleObtainTime()
  }

  // 获取视频长度
  const handleObtainTime = async () => {
    const list = meetingInfo;
    // console.log({list})
    // setAllVideoList(list)
    const start = Math.min.apply(Math, list.map(item => { return item.startTime }))
    const end = Math.max.apply(Math, list.map(item => { return item.endTime }))
    const time = end - start
    setVideoStartTime(start)
    setMaxTime(time)
    // console.log({start, end, time})
  }

  

  const handleMeeting = async info => {
    const userList = info
    // console.log('userList[0]', userList[0])

    // if (userList[0].mediaUrl) {
    // 筛选出候选人
    const candidateInfo = userList.filter(i => i.id.indexOf('c_') > -1)
    // console.log({candidateInfo})
    setCurrentVideoInfo({ ...candidateInfo[0] })
    setVideoList([...candidateInfo]) // 候选人列表
    setCopyVideoList(JSON.parse(JSON.stringify(candidateInfo)))
    // }
    // handleObtainTime(userList)
  }






  // 候选人切换变化
  const handleChangeCandidateVideo = (type) => {

    if (videoList.length === 1) {
      message.info('只有一个候选人哦~')
      return
    }
    let index = 0
    for (let i in copyVideoList) {
      if (copyVideoList[i].nickname === currentVideoInfo.nickname) {
        index = Number(i)
      }
    }
    // console.log(index, copyVideoList[index + 1], videoList)
    if (type === 'right') {
      if (index === (videoList.length - 1)) {
        childMethodRef.current.hanldeChangeListVideo(copyVideoList[0], videoList, 0, '1');
      } else {
        childMethodRef.current.hanldeChangeListVideo(copyVideoList[index + 1], videoList, index + 1, '1');
        // setCurrentVideoInfo(videoList[index + 1])
      }
    } else {

      if (index === (0)) {
        childMethodRef.current.hanldeChangeListVideo(copyVideoList[videoList.length - 1], videoList, videoList.length - 1, '1');
        // setCurrentVideoInfo(videoList[videoList.length - 1])
      } else {
        childMethodRef.current.hanldeChangeListVideo(copyVideoList[index - 1], videoList, index - 1, '1');
        // setCurrentVideoInfo(videoList[Number(index) - 1])
      }
    }
  }



  useEffect(() => {
    handleMeetingRoom()

  }, [])

  // console.log('currentVideoInfo', currentVideoInfo)

  return (
    <div className='analyze-container'>
      <div className='analyze-content'>
            <div className='playback-content'>
              <VideoLeft
                ref={childMethodRef}
                videoList={videoList}
                handleChangeCandidateVideo={handleChangeCandidateVideo}
                currentVideoInfo={currentVideoInfo}
                currentMasteroInfo={currentMasteroInfo}
                setCurrentVideoInfo={setCurrentVideoInfo}
                setCurrentMasterInfo={setCurrentMasterInfo}
                handleChangeMasterVideo={handleChangeMasterVideo}
                formatDuring={formatDuring}
                timeValue={timeValue}
                setTimeValue={setTimeValue}
                current={current}
                setIsPlay={setIsPlay}
                isPlay={isPlay}
                maxTime={maxTime}
              />
            </div>
      </div>
    </div>
  )
}

export default App;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/468789
推荐阅读
相关标签
  

闽ICP备14008679号