Commit b53b83f6 authored by liujiangnan's avatar liujiangnan

feat: 拖动问题

parent 7374b001
......@@ -221,7 +221,6 @@ cc.Class({
});
this.videoPlayer.node.on('completed', async () => {
console.log('completed');
// this.videoPlayer.currentTime = 0;
this._isPlayComplated = true;
this.playButton.node.active = false;
this.pauseButton.node.active = false;
......@@ -245,84 +244,36 @@ cc.Class({
this.barTag.off(cc.Node.EventType.TOUCH_START);
this.barTag.on(cc.Node.EventType.TOUCH_START, (e) => {
if (!this.videoPlayer.isPlaying()) {
return
}
if (!this._isReadyToPlay) {
return;
}
console.log("TOUCH_START");
this.userDragStart = true;
this.triggerInteractive()
});
this.barTag.off(cc.Node.EventType.TOUCH_MOVE);
this.barTag.on(cc.Node.EventType.TOUCH_MOVE,(e) => {
console.log("TOUCH_MOVE");
var delta = e.getDelta();
let newX = this.barTag.x+delta.x;
const worldPos = e.getLocation();
const localPos = this.barTag.parent.convertToNodeSpaceAR(worldPos);
let newX = localPos.x;
newX = Math.min(maxX, Math.max(newX, minX));
this.barTag.x = newX;
const percent = newX / maxX;
const dur = this.videoPlayer.getDuration();
this.currentTimeLabel.string = this.formatTime(percent * dur );
this.triggerInteractive()
this.videoPlayer.currentTime = percent * dur;
});
this.barTag.off(cc.Node.EventType.TOUCH_ENDED);
this.barTag.on(cc.Node.EventType.TOUCH_ENDED, (e) => {
console.log("TOUCH_ENDED");
this.userDragStart = false;
this.updateBarByPos(this.barTag.x);
this.triggerInteractive()
});
this.barTag.on(cc.Node.EventType.MOUSE_UP, (e) => {
console.log("MOUSE_UP");
this.userDragStart = false;
this.updateBarByPos(this.barTag.x);
this.triggerInteractive()
});
this.barTag.off(cc.Node.EventType.TOUCH_CANCEL);
this.barTag.on(cc.Node.EventType.TOUCH_CANCEL, (e) => {
console.log("TOUCH_CANCEL");
this.userDragStart = false;
this.updateBarByPos(this.barTag.x);
this.triggerInteractive()
});
// this.ProgressBar.off(cc.Node.EventType.TOUCH_START);
// this.ProgressBar.on(cc.Node.EventType.TOUCH_START, (e) => {
// console.log("==ProgressBar TOUCH_START==");
// const pos = e.getLocation();
// const pPos = this.ProgressBar.convertToNodeSpaceAR(pos);
// const newX = Math.min(maxX, Math.max(pPos.x, minX));
// this.updateBarByPos(newX);
// // console.log("ProgressBar TOUCH_START", newX);
// });
// this.videoPlayer.node.off(cc.Node.EventType.TOUCH_START);
// this.videoPlayer.node.on(cc.Node.EventType.TOUCH_START, (e) => {
// console.log("screen TOUCH_START");
// this.triggerInteractive()
// });
const pgBar = this.ProgressBar;
this.tw = new (function(){
this._tw = cc.tween(pgBar).delay(3).to(.6, {
opacity: 255
}).call(() => {
console.log('This is a callback');
this.running = false;
// this.displayed = false;
// this.tw.stop();
// this.tw.removeSelf()
// this.tw = null;
}),
this.running = false;
this.displayed = true;
this.start = () => {
this.running = true;
this.displayed = false;
pgBar.opacity = 255;
this._tw.start();
}
this.stop = () => {
this.running = false;
this.displayed = true;
this._tw.stop();
pgBar.opacity = 255;
}
});
},
async initView() {
......@@ -380,27 +331,15 @@ cc.Class({
window.dispatchEvent(new CustomEvent('resize'), true)
}
},
triggerInteractive() {
this.tw.stop();
this.ProgressBar.opacity = 255;
this.tw.start();
},
checkProgressBarStatus() {
if (this.videoPlayer.isPlaying()) {
if (this.tw.displayed) {
this.tw.start();
}
} else {
this.tw.stop();
this.ProgressBar.opacity = 255
}
},
updateBarByPos(newX) {
const maxX = this.ProgressBar.width;
const minX = 0;
const percent = newX / maxX;
// console.log(newX, percent);
if (percent > 1) {
percent = 1
}
const dur = this.videoPlayer.getDuration();
this.videoPlayer.currentTime = percent * dur
},
......@@ -463,26 +402,14 @@ cc.Class({
this.videoPlayer.node.y = 0;
// this.videoPlayer.node.active = true;
this.videoPlayer.play();
this.triggerInteractive()
},
pause(){
this.videoPlayer.pause();
this.triggerInteractive()
},
forward(){
this.videoPlayer.currentTime =this.videoPlayer.getImpl().currentTime() + 5;
this.triggerInteractive()
},
backward(){
this.videoPlayer.currentTime = this.videoPlayer.getImpl().currentTime() - 5;
this.triggerInteractive()
},
replay(){
this._isPlayComplated = false;
this.videoPlayer.currentTime = 0;
this.videoPlayer.play();
this.triggerInteractive();
},
playLocalAudio(audioName) {
......@@ -550,21 +477,11 @@ cc.Class({
// called every frame
update: function (dt) {
// if (this._isReadyToPlay) {
// const ct = this.videoPlayer.currentTime
// }
// if (this.wardState && this.videoPlayer.isPlaying()) {
// this.wardState = false;
// this.pause();
// }
if (this.videoPlayer) {
// console.log(this.userDragStart);
if (!this.userDragStart) {
const ct = this.videoPlayer.getImpl().currentTime();
this.updateBarByTime(ct);
}
this.checkProgressBarStatus();
const ct = this.videoPlayer.currentTime;
if (ct) {
this.updateBarByTime(ct);
}
if (this.videoPlayer.isPlaying()) {
if (this.playButton.node.active) {
this.playButton.node.active = false;
......
......@@ -18,7 +18,7 @@ export const defaultData = {
"name": "niao_tex.png"
}
},
// "video_url": "http://staging-teach.cdn.ireadabc.com/c8b49f6f032bd91a637df072c01ccaf7.mp4",
"video_url": "http://staging-teach.cdn.ireadabc.com/5d2e56f9c0d4307ab08df600d913b011.mp4",
"video_url": "http://staging-teach.cdn.ireadabc.com/c8b49f6f032bd91a637df072c01ccaf7.mp4",
// "video_url": "http://staging-teach.cdn.ireadabc.com/5d2e56f9c0d4307ab08df600d913b011.mp4",
"audioName": ""
};
\ No newline at end of file
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