Commit 4882ef2e authored by liujiangnan's avatar liujiangnan

feat: 配音合成

parent 82a36f98
import {
getVideoUrl, buttonOnClick,
getVideoUrl, buttonOnClick, playAudioByUrl,
} from "../script/util";
import { MyCocosSceneComponent } from "./MyCocosSceneComponent";
......@@ -37,15 +37,24 @@ export default class NewClass extends MyCocosSceneComponent {
}
onEnable () {
// this.videoplayer.remoteURL = "";
this.rowData = this.node["rowData"];
this.dot.x = this.dotX;
this.process.width = 0;
this.preloadRecorder();
this.prePlayIndex = 0;
getVideoUrl(this.rowData.video_url, (url) => {
this.videoplayer.remoteURL = url+`?t=${Date.now()}`;
})
}
preloadRecorder() {
const preloadArr = this.rowData.item_arr.map((item) => {
return {url: item.audio_url};
});
cc.assetManager.loadAny(preloadArr);
}
updateVideoStrip() {
if (!this.videoplayer?.isPlaying()) {
return;
......@@ -70,6 +79,9 @@ export default class NewClass extends MyCocosSceneComponent {
closeVideo() {
this.videoplayer.stop();
if (this.playAudioId) {
cc.audioEngine.stop(this.playAudioId);
}
this.dot.x = this.dotX;
this.process.width = 0;
cc.find(`Canvas/videoContainer`).active = false;
......@@ -85,11 +97,17 @@ export default class NewClass extends MyCocosSceneComponent {
buttonOnClick(this.playBtn, () => {
this.videoplayer.play();
if (this.playAudioId) {
cc.audioEngine.resume(this.playAudioId);
}
});
this.videoplayer.node.on('clicked', () => {
if (this.videoplayer.isPlaying()) {
this.videoplayer.pause();
if (this.playAudioId) {
cc.audioEngine.pause(this.playAudioId);
}
this.playBtn.active = true;
}
});
......@@ -105,7 +123,31 @@ export default class NewClass extends MyCocosSceneComponent {
});
}
prePlayIndex = 0;
playAudioId = null;
listenTimePlayRecorder() {
const item = this.rowData.item_arr[this.prePlayIndex];
if(!item) {
return;
}
const startTime = item.startTime;
const audio_url = item.audio_url;
if (this.videoplayer.currentTime>=startTime) {
this.prePlayIndex++;
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
if (err) {
console.error(err);
return;
}
this.playAudioId = cc.audioEngine.play(audioClip, false, 1);
});
}
}
update (dt) {
this.updateVideoStrip();
this.listenTimePlayRecorder();
}
}
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