Commit 4882ef2e authored by liujiangnan's avatar liujiangnan

feat: 配音合成

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