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

优化全屏进度条

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