Commit 783627e3 by zhanghaozhe

video

parent 5fb385f7
src/
\ No newline at end of file
...@@ -17,7 +17,6 @@ import Single from "src/components/detail/single"; ...@@ -17,7 +17,6 @@ import Single from "src/components/detail/single";
import SingleSuccess from "../detail/single/singleSuccess"; import SingleSuccess from "../detail/single/singleSuccess";
import './CustomPlayButton' import './CustomPlayButton'
let alert = Modal.alert let alert = Modal.alert
function ProgressShareModal(props) { function ProgressShareModal(props) {
...@@ -64,6 +63,8 @@ class Video extends Component { ...@@ -64,6 +63,8 @@ class Video extends Component {
video //video element video //video element
player //video player instance player //video player instance
currentVideoTimer
currentVideoExpireTime
courseID courseID
...@@ -75,8 +76,6 @@ class Video extends Component { ...@@ -75,8 +76,6 @@ class Video extends Component {
previousPlaybackRate = 1 previousPlaybackRate = 1
currentPlaybackRate = 1 currentPlaybackRate = 1
reconnect = true reconnect = true
// timeEnough = false
recordSocket recordSocket
recordTimer recordTimer
...@@ -89,7 +88,6 @@ class Video extends Component { ...@@ -89,7 +88,6 @@ class Video extends Component {
courseId: null, courseId: null,
videoList: [], videoList: [],
datum: [], datum: [],
currentVideoSrc: '',
activeIndex: 0, activeIndex: 0,
isAuth: true, isAuth: true,
course: {}, // course.course_id 为 0 或 '' 时 为免费课程 course: {}, // course.course_id 为 0 或 '' 时 为免费课程
...@@ -107,7 +105,8 @@ class Video extends Component { ...@@ -107,7 +105,8 @@ class Video extends Component {
showLimitFreePopup: false, showLimitFreePopup: false,
limitFreePopup: {}, limitFreePopup: {},
isShowNeverShowPopupOption: false, //限时免费课程 播放结束后是否显示"不再显示此弹框"选项 isShowNeverShowPopupOption: false, //限时免费课程 播放结束后是否显示"不再显示此弹框"选项
limitFreePopupVideos: JSON.parse(localStorage.getItem('limit-free-popup-videos')) limitFreePopupVideos: JSON.parse(localStorage.getItem('limit-free-popup-videos')),
currentVideoExpireTime: '',
} }
...@@ -123,9 +122,9 @@ class Video extends Component { ...@@ -123,9 +122,9 @@ class Video extends Component {
return return
} }
this.setState({ this.setState({
courseId: this.courseID courseId: this.courseID,
}) })
const {location, location: {state = {}}} = this.props; const {location: {state = {}}} = this.props;
if (state.oid) { if (state.oid) {
this.check(state.oid); this.check(state.oid);
} }
...@@ -157,7 +156,7 @@ class Video extends Component { ...@@ -157,7 +156,7 @@ class Video extends Component {
this.setState({ this.setState({
singleBox: true, singleBox: true,
singleType: 1, singleType: 1,
singMess: item singMess: item,
}) })
window.localStorage.setItem('singMess', JSON.stringify(item)) window.localStorage.setItem('singMess', JSON.stringify(item))
} }
...@@ -174,7 +173,7 @@ class Video extends Component { ...@@ -174,7 +173,7 @@ class Video extends Component {
return; return;
} else { } else {
this.setState({ this.setState({
singMess: JSON.parse(window.localStorage.getItem('singMess')) singMess: JSON.parse(window.localStorage.getItem('singMess')),
}) })
_this.intervalPayStatus = setInterval(function () { _this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => { http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
...@@ -223,7 +222,7 @@ class Video extends Component { ...@@ -223,7 +222,7 @@ class Video extends Component {
return return
} else { } else {
this.setState({ this.setState({
singMess: JSON.parse(window.localStorage.getItem('singMess')) singMess: JSON.parse(window.localStorage.getItem('singMess')),
}) })
// this.props.weixinPay(weixin_code) // this.props.weixinPay(weixin_code)
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => { http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
...@@ -238,7 +237,7 @@ class Video extends Component { ...@@ -238,7 +237,7 @@ class Video extends Component {
"nonceStr": data.nonceStr, //随机串 "nonceStr": data.nonceStr, //随机串
"package": data.package, "package": data.package,
"signType": data.signType, //微信签名方式: "signType": data.signType, //微信签名方式:
"paySign": data.paySign //微信签名 "paySign": data.paySign, //微信签名
}, },
function (res) { function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") { if (res.err_msg == "get_brand_wcpay_request:ok") {
...@@ -282,7 +281,7 @@ class Video extends Component { ...@@ -282,7 +281,7 @@ class Video extends Component {
} else { } else {
alert('支付失败') alert('支付失败')
} }
} },
) )
} }
...@@ -306,7 +305,7 @@ class Video extends Component { ...@@ -306,7 +305,7 @@ class Video extends Component {
// 判断支付是否成功 // 判断支付是否成功
check = (oid) => { check = (oid) => {
this.setState({ this.setState({
singMess: JSON.parse(window.localStorage.getItem('singMess')) singMess: JSON.parse(window.localStorage.getItem('singMess')),
}) })
http.get(`${API['base-api']}/class_order_status/${oid}`).then((res) => { http.get(`${API['base-api']}/class_order_status/${oid}`).then((res) => {
if (Number(res.data.data.errno) === 200) { if (Number(res.data.data.errno) === 200) {
...@@ -378,7 +377,7 @@ class Video extends Component { ...@@ -378,7 +377,7 @@ class Video extends Component {
let reconnect = setTimeout(function () { let reconnect = setTimeout(function () {
clearTimeout(reconnect); clearTimeout(reconnect);
reconnect = null; reconnect = null;
_this.ws = new WebSocket(PROCESS_URL); _this.ws = new WebSocket(API["process-api"]);
}, 500); }, 500);
} }
} }
...@@ -482,11 +481,17 @@ class Video extends Component { ...@@ -482,11 +481,17 @@ class Video extends Component {
errorDisplay: false, errorDisplay: false,
playbackRates: ['0.75', '1', '1.5', '2'], playbackRates: ['0.75', '1', '1.5', '2'],
controlBar: { controlBar: {
pictureInPictureToggle: false pictureInPictureToggle: false,
} },
}) })
this.player.addChild('CustomPlayButtonCover') this.player.addChild('CustomPlayButtonCover')
this.player.on('play', () => { this.player.on('play', () => {
let videoTime = window.sessionStorage.getItem('videoTimeBeforeReload')
if (videoTime) {
this.player.currentTime(videoTime)
window.sessionStorage.removeItem('videoTimeBeforeReload')
}
const {videoList, activeIndex, vCourseId, course = {}} = this.state const {videoList, activeIndex, vCourseId, course = {}} = this.state
// 当视频播放时 看是否是第一次播放(初次进入页面 刷新页面 切换视频 都是第一次播放 需要获取上次的播放时间) // 当视频播放时 看是否是第一次播放(初次进入页面 刷新页面 切换视频 都是第一次播放 需要获取上次的播放时间)
if (this.isCurrentVideoFirstPlay) { if (this.isCurrentVideoFirstPlay) {
...@@ -526,16 +531,26 @@ class Video extends Component { ...@@ -526,16 +531,26 @@ class Video extends Component {
this.timer = null; this.timer = null;
if (this.state.limitFreePopup.is_free) { if (this.state.limitFreePopup.is_free) {
this.setState({ this.setState({
showLimitFreePopup: true showLimitFreePopup: true,
}) })
} }
}) })
this.player.on('waiting', () => {
clearTimeout(this.currentVideoTimer)
this.currentVideoTimer = setTimeout(() => {
if (this.currentVideoExpireTime < new Date().getTime()) {
window.sessionStorage.setItem('videoTimeBeforeReload', this.player.currentTime())
this.getVideoSrc()
}
}, 3000)
})
} }
sendLastRecord = () => { sendLastRecord = () => {
http.post(`${API.home}/m/course/record_last_video`, { http.post(`${API.home}/m/course/record_last_video`, {
v_course_id: this.state.course['v_course_id'], v_course_id: this.state.course['v_course_id'],
video_id: this.state.videoList[this.state.activeIndex].id video_id: this.state.videoList[this.state.activeIndex].id,
}) })
} }
...@@ -552,6 +567,23 @@ class Video extends Component { ...@@ -552,6 +567,23 @@ class Video extends Component {
this.recordSocket = null this.recordSocket = null
} }
//请求签名视频地址
getVideoSrc = () => {
const {videoList, activeIndex} = this.state
let lesson = videoList[activeIndex]
http.get(`${API.home}/web/check_video/${lesson.id}/${lesson.v_course_id}`)
.then(res => {
const {data, code, msg} = res.data
let url = new URL(data.url).searchParams
if (code === 200) {
this.currentVideoExpireTime = url.has('Expires') && (Number(url.get('Expires')) * 1000)
this.setPlayerSrc(data.url)
} else {
Toast.info(msg)
}
})
}
// 选择新的视频 // 选择新的视频
selectVideo = index => { selectVideo = index => {
if (index === this.state.activeIndex) { if (index === this.state.activeIndex) {
...@@ -564,18 +596,18 @@ class Video extends Component { ...@@ -564,18 +596,18 @@ class Video extends Component {
this.setState( this.setState(
{ {
activeIndex: index activeIndex: index,
}, },
() => { () => {
if (this.hasAuth(this.state.activeIndex)) { if (this.hasAuth(this.state.activeIndex)) {
this.setPlayerSrc(this.state.videoList[index]['play_url']) this.getVideoSrc()
this.sendLastRecord() this.sendLastRecord()
this.playVideo() this.playVideo()
} else { } else {
this.getCoursePrice(); this.getCoursePrice();
} }
} },
); );
} }
...@@ -588,7 +620,7 @@ class Video extends Component { ...@@ -588,7 +620,7 @@ class Video extends Component {
if (getParam('video_id')) { if (getParam('video_id')) {
url = `${API.home}/m/course/play/${this.courseID + '?video_id=' + getParam('video_id')}` url = `${API.home}/m/course/play/${this.courseID + '?video_id=' + getParam('video_id')}`
http.post(`${API['base-api']}/sys/get_class_audition`, { http.post(`${API['base-api']}/sys/get_class_audition`, {
video_id: getParam('video_id') video_id: getParam('video_id'),
}) })
} else { } else {
url = `${API.home}/m/course/play/${this.courseID}` url = `${API.home}/m/course/play/${this.courseID}`
...@@ -599,28 +631,25 @@ class Video extends Component { ...@@ -599,28 +631,25 @@ class Video extends Component {
this.setState( this.setState(
state => ({ state => ({
videoList: data['lessons'], videoList: data['lessons'],
currentVideoSrc: data['lessons'][state.activeIndex]['play_url'],
course: data.course, course: data.course,
courseId: data.course['course_id'], courseId: data.course['course_id'],
vCourseId: data.course['v_course_id'], vCourseId: data.course['v_course_id'],
title: data.course['course_title'], title: data.course['course_title'],
isLoading: false isLoading: false,
}), }),
this.playSetup this.playSetup,
) )
data.course.course_id && this.getLimitFreePopup(data.course.course_id) data.course.course_id && this.getLimitFreePopup(data.course.course_id)
} else { } else {
Toast.info(data.msg) Toast.info(data.msg)
} }
} },
) )
} }
playSetup = () => { playSetup = () => {
// is_aist,是否AI特训营 // is_aist,是否AI特训营
const {course = {}} = this.state; const {course = {}} = this.state;
// if (Number(course.course_id) === 0 || course.course_id === '') {
// }else{
let _this = this; let _this = this;
this.setupWS(); this.setupWS();
this.setupTimer(); this.setupTimer();
...@@ -629,12 +658,11 @@ class Video extends Component { ...@@ -629,12 +658,11 @@ class Video extends Component {
scheduleTime = null; scheduleTime = null;
_this.countSchedule(); // 刚进入页面的时候 就计算进度 先获取视频列表getVideoList 获取列表后 播放选择的视频 然后计算进度 _this.countSchedule(); // 刚进入页面的时候 就计算进度 先获取视频列表getVideoList 获取列表后 播放选择的视频 然后计算进度
}, 1000); }, 1000);
// }
let index = this.getLastVideoIndex(course.last_video_id); let index = this.getLastVideoIndex(course.last_video_id);
index = index >= 0 ? index : 0; index = index >= 0 ? index : 0;
this.setState( this.setState(
{ {
activeIndex: index activeIndex: index,
}, },
() => { () => {
if (this.lessonAvailable(index)) { if (this.lessonAvailable(index)) {
...@@ -651,10 +679,10 @@ class Video extends Component { ...@@ -651,10 +679,10 @@ class Video extends Component {
text: 'OK', text: 'OK',
onPress: () => { onPress: () => {
this.props.history.push('/') this.props.history.push('/')
} },
}]) }])
} }
} },
); );
} }
...@@ -665,8 +693,9 @@ class Video extends Component { ...@@ -665,8 +693,9 @@ class Video extends Component {
} }
this.player.src({ this.player.src({
src, src,
type: 'application/x-mpegURL' type: 'application/x-mpegURL',
}) })
this.player.play()
} }
playVideo = () => { playVideo = () => {
...@@ -684,7 +713,7 @@ class Video extends Component { ...@@ -684,7 +713,7 @@ class Video extends Component {
if (data.code === 200) { if (data.code === 200) {
this.setState({ this.setState({
datum: data.data datum: data.data,
}) })
} else { } else {
...@@ -704,17 +733,16 @@ class Video extends Component { ...@@ -704,17 +733,16 @@ class Video extends Component {
const {data} = res const {data} = res
if (data.code === 200) { if (data.code === 200) {
this.setState({ this.setState({
salePrice: data.data['sale_price'] salePrice: data.data['sale_price'],
}) })
} }
}) })
} }
playWithAuth = () => { playWithAuth = () => {
const {videoList, activeIndex} = this.state const {activeIndex} = this.state
if (this.hasAuth(activeIndex)) { if (this.hasAuth(activeIndex)) {
this.setPlayerSrc(videoList[activeIndex]['play_url']) this.getVideoSrc()
} }
} }
...@@ -725,12 +753,12 @@ class Video extends Component { ...@@ -725,12 +753,12 @@ class Video extends Component {
if (lesson['video_auth']) { if (lesson['video_auth']) {
this.setState({ this.setState({
isAuth: true isAuth: true,
}) })
return true return true
} else { } else {
this.setState({ this.setState({
isAuth: false isAuth: false,
}) })
return false return false
...@@ -739,7 +767,7 @@ class Video extends Component { ...@@ -739,7 +767,7 @@ class Video extends Component {
getLimitFreePopup = id => { getLimitFreePopup = id => {
http.post(`${API.home}/sys/popup`, { http.post(`${API.home}/sys/popup`, {
course_id: id course_id: id,
}) })
.then(res => { .then(res => {
const {code, msg, data} = res.data const {code, msg, data} = res.data
...@@ -748,7 +776,7 @@ class Video extends Component { ...@@ -748,7 +776,7 @@ class Video extends Component {
const {courseId, limitFreePopupVideos} = this.state const {courseId, limitFreePopupVideos} = this.state
this.setState({ this.setState({
limitFreePopup: data, limitFreePopup: data,
isShowNeverShowPopupOption: limitFreePopupVideos ? limitFreePopupVideos.includes(courseId) : false isShowNeverShowPopupOption: limitFreePopupVideos ? limitFreePopupVideos.includes(courseId) : false,
}) })
} else { } else {
...@@ -761,13 +789,13 @@ class Video extends Component { ...@@ -761,13 +789,13 @@ class Video extends Component {
return return
} }
http.post(`${API.home}/sys/checklist`, { http.post(`${API.home}/sys/checklist`, {
course_id: this.state.course.course_id course_id: this.state.course.course_id,
}) })
.then(res => { .then(res => {
const {code, msg} = res.data const {code, msg} = res.data
if (code === 200) { if (code === 200) {
this.setState({ this.setState({
limitFreePopup: {...this.state.limitFreePopup, is_free: 0} limitFreePopup: {...this.state.limitFreePopup, is_free: 0},
}) })
} else { } else {
...@@ -789,7 +817,7 @@ class Video extends Component { ...@@ -789,7 +817,7 @@ class Video extends Component {
singleType, singleType,
showLimitFreePopup, showLimitFreePopup,
limitFreePopup, limitFreePopup,
isShowNeverShowPopupOption isShowNeverShowPopupOption,
} = this.state; } = this.state;
let toHref = ''; let toHref = '';
if (location.state && location.state.to && location.state.to === 'detail') { if (location.state && location.state.to && location.state.to === 'detail') {
...@@ -801,8 +829,8 @@ class Video extends Component { ...@@ -801,8 +829,8 @@ class Video extends Component {
toHref ? history.push( toHref ? history.push(
toHref, toHref,
{ {
to: 'classify' to: 'classify',
} },
) : history.go(-1) ) : history.go(-1)
}}/> }}/>
<Loading isLoading={this.state.isLoading}> <Loading isLoading={this.state.isLoading}>
...@@ -895,7 +923,7 @@ class Video extends Component { ...@@ -895,7 +923,7 @@ class Video extends Component {
<Switch> <Switch>
<Redirect exact from={'/play'} to={{ <Redirect exact from={'/play'} to={{
pathname: '/play/video', pathname: '/play/video',
search: location.search search: location.search,
}}/> }}/>
<Route <Route
path={`${match.path}/video`} path={`${match.path}/video`}
...@@ -945,7 +973,7 @@ class Video extends Component { ...@@ -945,7 +973,7 @@ class Video extends Component {
</span> </span>
<input type="checkbox" id={'no-prompt'} onChange={(e) => { <input type="checkbox" id={'no-prompt'} onChange={(e) => {
this.setState({ this.setState({
limitFreeNoPromptChecked: e.target.checked limitFreeNoPromptChecked: e.target.checked,
}) })
}}/> }}/>
<span>本课程不再提示</span> <span>本课程不再提示</span>
...@@ -956,11 +984,11 @@ class Video extends Component { ...@@ -956,11 +984,11 @@ class Video extends Component {
<i className={'close-btn iconfont iconiconfront-2'} onClick={() => { <i className={'close-btn iconfont iconiconfront-2'} onClick={() => {
this.setState({ this.setState({
showLimitFreePopup: false, showLimitFreePopup: false,
isShowNeverShowPopupOption: true isShowNeverShowPopupOption: true,
}) })
const {courseId, limitFreePopupVideos} = this.state const {courseId, limitFreePopupVideos} = this.state
localStorage.setItem('limit-free-popup-videos', JSON.stringify( localStorage.setItem('limit-free-popup-videos', JSON.stringify(
limitFreePopupVideos ? [...limitFreePopupVideos, courseId] : [courseId] limitFreePopupVideos ? [...limitFreePopupVideos, courseId] : [courseId],
)) ))
this.checkNeverShowLimitFreePopup() this.checkNeverShowLimitFreePopup()
}}/> }}/>
...@@ -975,5 +1003,5 @@ class Video extends Component { ...@@ -975,5 +1003,5 @@ class Video extends Component {
export default connect( export default connect(
state => ({user: state.user}), state => ({user: state.user}),
null null,
)(Video); )(Video);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment