Commit aa313722 authored by limingzhe's avatar limingzhe

feat: 尝试使用优化版本的视频地址

parent d008ca63
......@@ -88,9 +88,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.pauseBtn.active = false;
}
async refreshBtnState() {
refreshBtnState() {
await asyncDelay(0.01);
// await asyncDelay(0.01);
if (this.video.isPlaying()) {
this.pauseBtn.active = true;
......@@ -117,16 +117,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
video = null
initVideo() {
console.log(' in initVideo...')
if (this.data.video_url) {
this.initVideoRemote();
this.getVideoUrl( (url) => {
this.initVideoRemote(url);
})
}
this.video.node.on('completed', () => {
console.log(' in completed!!!!')
this.videoPlayEnd();
})
}
getVideoUrl(callback) {
const url1 = this.data.video_url;
const url2 = url1.replace(/.mp4$/g, "_l.mp4");
this.httpHeadCall(url2, (success) => {
if (success) {
console.log('return url2: ', url2);
callback(url2);
} else {
console.log('return url1: ', url1);
callback(url1);
}
})
}
isPlayEnd = null
......@@ -144,7 +161,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
initVideoRemote() {
initVideoRemote(url) {
console.log(' in initVideoRemote')
const videoLocalNode = cc.find("Canvas/videoBase/videoLocal");
......@@ -158,7 +176,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
video.resourceType = cc.VideoPlayer.ResourceType.REMOTE;
video.remoteURL = this.data.video_url;
video.remoteURL = url;
// video.isFullscreen = true;
video.stayOnBottom = true;
......@@ -189,12 +207,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
const sy = canvas.height / height;
video.node.scale = Math.min(sx, sy);
console.log('canvas: ', canvas);
console.log('canvas.width: ', canvas.width);
console.log('e.node.width: ', e.node.width);
console.log('sx: ', sx);
console.log('sy: ', sy);
console.log('scale: ', video.node.scale);
// console.log('canvas: ', canvas);
// console.log('canvas.width: ', canvas.width);
// console.log('e.node.width: ', e.node.width);
// console.log('sx: ', sx);
// console.log('sy: ', sy);
// console.log('scale: ', video.node.scale);
video.play();
// window["air"].hideAirClassLoading();
......@@ -222,9 +240,61 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
this.video.node.on('completed', () => {
console.log(' in completed!!!!')
this.videoPlayEnd();
})
}
httpHeadCall(requsetUrl: string, callback) {
let xhr = new XMLHttpRequest();
console.log("Status: Send Post Request to " + requsetUrl);
try {
xhr.onreadystatechange = () => {
try{
console.log('xhr.readyState: ', xhr.readyState);
if (xhr.readyState == 4) {
if ((xhr.status >= 200 && xhr.status < 400)) {
callback(true);
} else {
callback(false);
}
}
}catch(e){
cc.error(e)
}
};
xhr.open("HEAD", requsetUrl, true);
// xhr.setRequestHeader('content-type', 'application/json');
// xhr.setRequestHeader('token', this.token);
// xhr.send(JSON.stringify(requestData));
xhr.send();
xhr.timeout = 15000;
xhr.onerror = (e) => {
console.log("汪汪汪 posterror", e);
callback(false);
};
xhr.ontimeout = (e) => {
console.log("汪汪汪 ontimeout", e);
callback(false);
};
} catch (e) {
cc.error("Send Get Request error: ", e)
}
}
......
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