Commit 121122e9 authored by 李维's avatar 李维

优化全屏进度条

parent ada264be
...@@ -164,13 +164,13 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -164,13 +164,13 @@ 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.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.opacity = 255; this.fullscreenVideoControls.emit("show");
if (this.time1) { if (this.time1) {
clearTimeout(this.time1); clearTimeout(this.time1);
} }
this.time1 = setTimeout(() => { this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false; this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.opacity = 0; this.fullscreenVideoControls.emit("hide");
}, 6000); }, 6000);
} }
}); });
...@@ -179,13 +179,13 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -179,13 +179,13 @@ export default class VideoPlayerComponent extends cc.Component {
console.log('touchstarted'); console.log('touchstarted');
if (this.isVideoFull) { if (this.isVideoFull) {
this.videoPlayer.stayOnBottom = true; this.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.opacity = 255; this.fullscreenVideoControls.emit("show");
if (this.time1) { if (this.time1) {
clearTimeout(this.time1); clearTimeout(this.time1);
} }
this.time1 = setTimeout(() => { this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false; this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.opacity = 0; this.fullscreenVideoControls.emit("hide");
}, 6000); }, 6000);
} }
}); });
...@@ -194,13 +194,13 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -194,13 +194,13 @@ export default class VideoPlayerComponent extends cc.Component {
console.log('touchstarted'); console.log('touchstarted');
if (this.isVideoFull) { if (this.isVideoFull) {
this.videoPlayer.stayOnBottom = true; this.videoPlayer.stayOnBottom = true;
this.fullscreenVideoControls.opacity = 255; this.fullscreenVideoControls.emit("show");
if (this.time1) { if (this.time1) {
clearTimeout(this.time1); clearTimeout(this.time1);
} }
this.time1 = setTimeout(() => { this.time1 = setTimeout(() => {
this.videoPlayer.stayOnBottom = false; this.videoPlayer.stayOnBottom = false;
this.fullscreenVideoControls.opacity = 0; this.fullscreenVideoControls.emit("hide");
}, 6000); }, 6000);
} }
}); });
...@@ -266,6 +266,11 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -266,6 +266,11 @@ export default class VideoPlayerComponent extends cc.Component {
this.fullscreenVideoControls.on("exit_fullscreen", ()=>{ this.fullscreenVideoControls.on("exit_fullscreen", ()=>{
this.exitFullScreen() this.exitFullScreen()
}) })
this.fullscreenVideoControls.on("draging_progress", (opt)=>{
const {percent} = opt;
const dur = this.videoPlayer.getDuration();
this.videoPlayer.currentTime = percent * dur;
})
this.fullscreenVideoControls.on("switch_clarity", (clarity="h")=>{ this.fullscreenVideoControls.on("switch_clarity", (clarity="h")=>{
}) })
...@@ -513,6 +518,11 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -513,6 +518,11 @@ export default class VideoPlayerComponent extends cc.Component {
percent = 1; percent = 1;
} }
this.ProgressBar.getComponent(cc.ProgressBar).progress = percent; this.ProgressBar.getComponent(cc.ProgressBar).progress = percent;
this.fullscreenVideoControls.emit("setProgress", {
percent: percent,
startTime: ct,
endTime: dur,
})
const maxX = this.ProgressBar.width; const maxX = this.ProgressBar.width;
const minX = 0; const minX = 0;
let newX = percent * maxX; let newX = percent * maxX;
...@@ -583,7 +593,6 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -583,7 +593,6 @@ export default class VideoPlayerComponent extends cc.Component {
this.playButton.node.active = false; this.playButton.node.active = false;
this.pauseButton.node.active = true; this.pauseButton.node.active = true;
} }
pause() { pause() {
...@@ -627,7 +636,7 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -627,7 +636,7 @@ export default class VideoPlayerComponent extends cc.Component {
// 隐藏中间层返回按钮 // 隐藏中间层返回按钮
this.showHideMiddleLayerBackBtn(false); this.showHideMiddleLayerBackBtn(false);
this.isVideoFull = true; this.isVideoFull = true;
this.fullscreenVideoControls.opacity = 255; this.fullscreenVideoControls.emit("show");
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;
...@@ -680,7 +689,7 @@ export default class VideoPlayerComponent extends cc.Component { ...@@ -680,7 +689,7 @@ export default class VideoPlayerComponent extends cc.Component {
// 取消视频在最底部 // 取消视频在最底部
this.videoPlayer.stayOnBottom = false; this.videoPlayer.stayOnBottom = false;
// 隐藏全屏视频控制条 // 隐藏全屏视频控制条
this.fullscreenVideoControls.opacity = 0; this.fullscreenVideoControls.emit("hide");
// 显示正常视频控制条 // 显示正常视频控制条
this.videoControls.active = true; this.videoControls.active = true;
// 显示全屏按钮 // 显示全屏按钮
......
...@@ -25,11 +25,30 @@ export default class NewClass extends cc.Component { ...@@ -25,11 +25,30 @@ export default class NewClass extends cc.Component {
@property(cc.Node) @property(cc.Node)
label_title: cc.Node = null; label_title: cc.Node = null;
@property(cc.Node)
progressBg: cc.Node = null;
@property(cc.Node)
progressCurrent: cc.Node = null;
@property(cc.Node)
progressDot: cc.Node = null;
@property(cc.Node)
startTime: cc.Node = null;
@property(cc.Node)
endTime: cc.Node = null;
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// onLoad () {} // onLoad () {}
currentTime = null;
winWidth = 0;
start () { start () {
this.initdDrag();
this.winWidth = cc.find("/Canvas").width;
this.node.off("inFullscreen") this.node.off("inFullscreen")
this.node.on("inFullscreen", (opt)=>{ this.node.on("inFullscreen", (opt)=>{
const {isPlaying, title} = opt; const {isPlaying, title} = opt;
...@@ -37,6 +56,22 @@ export default class NewClass extends cc.Component { ...@@ -37,6 +56,22 @@ export default class NewClass extends cc.Component {
this.btn_play.active = !isPlaying; this.btn_play.active = !isPlaying;
this.btn_pause.active = isPlaying; this.btn_pause.active = isPlaying;
}) })
this.node.on("setProgress", (opt)=>{
const {percent, startTime, endTime} = opt;
if(this.currentTime != Math.floor(startTime)) {
this.setProgress(percent, startTime, endTime)
this.currentTime = Math.floor(startTime)
}
})
this.node.on("show", (opt)=>{
this.show()
})
this.node.on("hide", (opt)=>{
this.hide()
})
} }
onPlayClick() { onPlayClick() {
...@@ -58,5 +93,113 @@ export default class NewClass extends cc.Component { ...@@ -58,5 +93,113 @@ export default class NewClass extends cc.Component {
onExitFullscreenClick() { onExitFullscreenClick() {
this.node.emit("exit_fullscreen") this.node.emit("exit_fullscreen")
} }
setProgress(percent, startTime, endTime) {
if(percent < 0) {
percent = 0
} else if(percent >1) {
percent = 1;
}
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);
}
if(endTime != undefined && startTime != null) {
this.endTime.getComponent(cc.Label).string = this.formatSeconds(endTime);
}
}
show(){
this.node.opacity = 255;
this.node.x = 0;
}
hide(){
this.node.opacity = 255;
this.node.x = -this.winWidth;
}
formatSeconds (value) {
const checkZero = (value) => {
if(value < 1) {
return 0
} else {
return Math.floor(value)
}
}
const fix2 = (value) => {
if(value < 10) {
return `0${value}`
} else {
return `${value}`
}
}
const hourSec = 60 * 60;
const minuteSec = 60;
const secSec = 1;
let hour = checkZero(value / hourSec);
let minute = checkZero((value - (hour * hourSec)) / minuteSec)
let second = checkZero((value - (hour * hourSec + minute * minuteSec)) / secSec)
let timeStr = ""
if(hour > 0) {
timeStr += fix2(hour) + ":";
}
if(minute > 0) {
timeStr += fix2(minute) + ":";
} else {
timeStr +="00:";
}
if(second > 0) {
timeStr += fix2(second);
} else {
timeStr +="00";
}
return timeStr
}
draging = false;
initdDrag() {
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.progressDot.off(cc.Node.EventType.TOUCH_MOVE);
this.progressDot.on(cc.Node.EventType.TOUCH_MOVE, (e) => {
const worldPos = e.getLocation();
const localPos = this.progressDot.parent.convertToNodeSpaceAR(worldPos);
let percent = (localPos.x + this.progressBg.width / 2) / this.progressBg.width;
if(percent < 0) {
percent = 0
} else if(percent >1) {
percent = 1;
}
this.node.emit("draging_progress", {percent});
this.setProgress(percent, null, null);
});
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.node.off(cc.Node.EventType.MOUSE_UP);
this.node.on(cc.Node.EventType.MOUSE_UP, (e) => {
this.draging = false;
this.node.emit("play");
});
}
// update (dt) {} // update (dt) {}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": true,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 64, "width": 64,
......
{
"ver": "2.3.5",
"uuid": "4b46edb4-08e6-4d09-9ae8-4f9daeec2d4c",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": true,
"genMipmaps": false,
"packable": true,
"width": 64,
"height": 64,
"platformSettings": {},
"subMetas": {
"icon_player_dot": {
"ver": "1.0.4",
"uuid": "ecafbd46-ac07-42d6-9ce3-d0e67da4e817",
"rawTextureUuid": "4b46edb4-08e6-4d09-9ae8-4f9daeec2d4c",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 16,
"trimY": 16,
"width": 32,
"height": 32,
"rawWidth": 64,
"rawHeight": 64,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": true,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 64, "width": 64,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": true,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 64, "width": 64,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": true,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 64, "width": 64,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": true,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 64, "width": 64,
......
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