Commit 61c13b34 authored by 李维's avatar 李维

优化全屏进度条

parent 121122e9
......@@ -163,45 +163,25 @@ export default class VideoPlayerComponent extends cc.Component {
this.videoPlayer.node.on('clicked', () => {
if (this.isVideoFull) {
this.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.emit("show");
if (this.time1) {
clearTimeout(this.time1);
}
this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.emit("hide");
}, 6000);
this.videoPlayer.stayOnBottom = true;
}
});
this.videoPlayer.node.on('touchstarted', () => {
console.log('touchstarted');
if (this.isVideoFull) {
this.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.emit("show");
if (this.time1) {
clearTimeout(this.time1);
}
this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.emit("hide");
}, 6000);
this.videoPlayer.stayOnBottom = true;
}
});
this.videoPlayer.node.on(cc.Node.EventType.TOUCH_START, () => {
console.log('touchstarted');
if (this.isVideoFull) {
this.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.emit("show");
if (this.time1) {
clearTimeout(this.time1);
}
this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.emit("hide");
}, 6000);
this.videoPlayer.stayOnBottom = true;
}
});
......@@ -256,6 +236,7 @@ export default class VideoPlayerComponent extends cc.Component {
}
}
// 初始化全屏视频控制条
initFullScreenControls() {
this.fullscreenVideoControls.on("play", ()=>{
this.play()
......@@ -263,6 +244,9 @@ export default class VideoPlayerComponent extends cc.Component {
this.fullscreenVideoControls.on("pause", ()=>{
this.pause()
})
this.fullscreenVideoControls.on("hide", ()=>{
this.videoPlayer.stayOnBottom = false;
})
this.fullscreenVideoControls.on("exit_fullscreen", ()=>{
this.exitFullScreen()
})
......@@ -270,6 +254,10 @@ export default class VideoPlayerComponent extends cc.Component {
const {percent} = opt;
const dur = this.videoPlayer.getDuration();
this.videoPlayer.currentTime = percent * dur;
this.fullscreenVideoControls.emit("tips", {
startTime: this.videoPlayer.currentTime,
endTime: dur
})
})
this.fullscreenVideoControls.on("switch_clarity", (clarity="h")=>{
......@@ -493,6 +481,7 @@ export default class VideoPlayerComponent extends cc.Component {
}
this.initListener();
this.initFullScreenControls();
this.videoPlayer.stayOnBottom = true;
}
updateBarByPos(newX: number) {
......@@ -579,6 +568,7 @@ export default class VideoPlayerComponent extends cc.Component {
play() {
if (!this._isReadyToPlay) {
console.log("视频还未准备好")
return;
}
......@@ -605,6 +595,7 @@ export default class VideoPlayerComponent extends cc.Component {
}
backward() {
}
replay() {
......@@ -619,7 +610,6 @@ export default class VideoPlayerComponent extends cc.Component {
cc.audioEngine.playEffect(audio.clip, false);
}
time1: any = null;
isVideoFull: boolean = false;
tempPos: any = null;
......@@ -637,6 +627,7 @@ export default class VideoPlayerComponent extends cc.Component {
this.showHideMiddleLayerBackBtn(false);
this.isVideoFull = true;
this.fullscreenVideoControls.emit("show");
this.videoPlayer.stayOnBottom = true;
this.videoControls.active = false;
cc.find(`Canvas/title`).active = false;
cc.find('Canvas/pageButton').active = false;
......@@ -647,7 +638,6 @@ export default class VideoPlayerComponent extends cc.Component {
})
}, 1);
this.videoPlayer.stayOnBottom = true;
const videoContainer = cc.find('Canvas/video_node');
this.tempPos.videoPos = {
x: videoContainer.x,
......@@ -670,11 +660,7 @@ export default class VideoPlayerComponent extends cc.Component {
const videoNode = cc.find("Canvas/VideoNode");
const widget = videoNode.getComponent(cc.Widget)
widget.enabled = true;
this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false;
}, 3000);
widget.enabled = true;
}
exitFullScreen() {
......@@ -686,10 +672,6 @@ export default class VideoPlayerComponent extends cc.Component {
this.showHideMiddleLayerBackBtn(true);
// 标记退出全屏
this.isVideoFull = false;
// 取消视频在最底部
this.videoPlayer.stayOnBottom = false;
// 隐藏全屏视频控制条
this.fullscreenVideoControls.emit("hide");
// 显示正常视频控制条
this.videoControls.active = true;
// 显示全屏按钮
......@@ -731,15 +713,9 @@ export default class VideoPlayerComponent extends cc.Component {
controlBg.opacity = 255;
controlBg.width = 1259;
if (this.time1) {
clearTimeout(this.time1);
}
}
onDestroy() {
if (this.time1) {
clearTimeout(this.time1);
}
// 显示中间层返回按钮
this.showHideMiddleLayerBackBtn(true);
}
......
......@@ -40,12 +40,16 @@ export default class NewClass extends cc.Component {
@property(cc.Node)
endTime: cc.Node = null;
@property(cc.Node)
centerInfo: cc.Node = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
currentTime = null;
winWidth = 0;
hideSetTimeoutId= null;
start () {
this.initdDrag();
this.winWidth = cc.find("/Canvas").width;
......@@ -69,9 +73,20 @@ export default class NewClass extends cc.Component {
this.show()
})
this.node.on("hide", (opt)=>{
this.hide()
// this.node.on("hide", (opt)=>{
// this.hide()
// })
this.node.on("tips", (opt)=>{
const {message, startTime, endTime} = opt
if(message) {
this.showTipInfo(message ? message : "")
} else if(this.checkNumber(startTime) && this.checkNumber(endTime)) {
this.showTipInfo(`${this.formatTimeShow(startTime)} / ${this.formatTimeShow(endTime)}`)
}
})
}
onPlayClick() {
......@@ -91,7 +106,9 @@ export default class NewClass extends cc.Component {
}
onExitFullscreenClick() {
this.node.emit("exit_fullscreen")
this.node.emit("exit_fullscreen");
this.hide()
this.cleanMyTimeout()
}
setProgress(percent, startTime, endTime) {
......@@ -104,24 +121,54 @@ export default class NewClass extends cc.Component {
this.progressCurrent.width = this.progressBg.width * percent;
this.progressDot.x = -this.progressBg.width / 2 + this.progressCurrent.width
if(startTime != undefined && startTime != null) {
this.startTime.getComponent(cc.Label).string = this.formatSeconds(startTime);
this.startTime.getComponent(cc.Label).string = this.formatTimeShow(startTime);
}
if(endTime != undefined && startTime != null) {
this.endTime.getComponent(cc.Label).string = this.formatSeconds(endTime);
this.endTime.getComponent(cc.Label).string = this.formatTimeShow(endTime);
}
}
show(){
this.node.opacity = 255;
this.node.x = 0;
this.cleanMyTimeout()
this.hideSetTimeoutId = setTimeout(() => {
this.hide()
}, 5000);
}
hide(){
this.node.emit("hide");
this.node.opacity = 255;
this.node.x = -this.winWidth;
}
formatSeconds (value) {
centerTipInfoSettimeoutId = null;
showTipInfo(text){
cc.find("/text", this.centerInfo).getComponent(cc.Label).string = text;
this.centerInfo.active = true;
if(this.centerTipInfoSettimeoutId) {
clearTimeout(this.centerTipInfoSettimeoutId)
this.centerTipInfoSettimeoutId = null;
}
this.centerTipInfoSettimeoutId = setTimeout(()=>{
this.centerInfo.active = false;
}, 1000)
}
cleanMyTimeout() {
if(this.hideSetTimeoutId) {
clearTimeout(this.hideSetTimeoutId);
this.hideSetTimeoutId = null;
}
}
checkNumber(val) {
const reg = /^[0-9]+.?[0-9]*/;
return reg.test(val)
}
formatTimeShow (value) {
const checkZero = (value) => {
if(value < 1) {
return 0
......@@ -170,7 +217,7 @@ export default class NewClass extends cc.Component {
this.progressDot.off(cc.Node.EventType.TOUCH_START);
this.progressDot.on(cc.Node.EventType.TOUCH_START, (e) => {
this.draging = true;
this.node.emit("pause")
this.node.emit("pause");
});
this.progressDot.off(cc.Node.EventType.TOUCH_MOVE);
......@@ -184,20 +231,23 @@ export default class NewClass extends cc.Component {
percent = 1;
}
this.node.emit("draging_progress", {percent});
this.centerInfo.active = true;
this.setProgress(percent, null, null);
this.show()
});
this.node.off(cc.Node.EventType.TOUCH_END);
this.node.on(cc.Node.EventType.TOUCH_END, (e) => {
this.draging = false;
this.node.emit("play")
this.centerInfo.active = false;
});
this.node.off(cc.Node.EventType.MOUSE_UP);
this.node.on(cc.Node.EventType.MOUSE_UP, (e) => {
this.draging = false;
this.node.emit("play");
this.centerInfo.active = false;
});
}
......
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