Commit 9e115bd2 authored by liujiangnan's avatar liujiangnan

feat: 视频高清处理

parent 1dccea74
...@@ -83,6 +83,63 @@ cc.Class({ ...@@ -83,6 +83,63 @@ cc.Class({
cc.director['_scene'].height = frameSize.height; cc.director['_scene'].height = frameSize.height;
}, },
getVideoUrl(callback) {
const url1 = this.data.video_url;
const url2 = url1.replace(/.mp4$/g, "_h.mp4");
this.httpHeadCall(url2, (success) => {
if (success) {
console.log('return url2: ', url2);
callback(url2);
} else {
console.log('return url1: ', url1);
callback(url1);
}
})
},
httpHeadCall(requsetUrl, 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) {
console.log(e)
}
};
xhr.open("HEAD", requsetUrl, true);
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) {
console.log("Send Get Request error: ", e)
}
},
// use this for initialization // use this for initialization
onLoad () { onLoad () {
...@@ -250,8 +307,10 @@ cc.Class({ ...@@ -250,8 +307,10 @@ cc.Class({
getData(async (data) => { getData(async (data) => {
console.log('data:', JSON.stringify(data)); console.log('data:', JSON.stringify(data));
this.data = data || this.getDefaultData(); this.data = data || this.getDefaultData();
this.getVideoUrl(videoUrl => {
this.data.video_url = videoUrl;
this.videoPlayer.remoteURL = this.data.video_url; this.videoPlayer.remoteURL = this.data.video_url;
// this.preload() });
await this.initView(); await this.initView();
if (window && window["air"]) { if (window && window["air"]) {
window["air"].hideAirClassLoading(); window["air"].hideAirClassLoading();
...@@ -356,17 +415,6 @@ cc.Class({ ...@@ -356,17 +415,6 @@ cc.Class({
this.triggerInteractive(); this.triggerInteractive();
}, },
preload() {
cc.assetManager.loadAny({url: this.data.video_url}, {cacheAsset: true}, null, (err, data) => {
console.log(' preload data, ', data);
// typeof
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
});
},
playLocalAudio(audioName) { playLocalAudio(audioName) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAll();
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource); const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
......
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