Closed ivangusev closed 7 months ago
@ivangusev Currently WVC supports the following methods to set audio:
wvc.createSingleVideo({ ... }).addAudio({ ... });
captureCtx.addAudio({ ... })
on the page<audio>
element into the DOM treeIf you want to terminate the video capture when the audio playback ends, this may not be easy to control. The most direct method is to set the video duration to be the same as the audio duration, which requires predicting the audio duration.
Another solution is to use captureCtx.currentTime
on the page to determine whether the audio duration is currently reached, and when the duration is reached, set captureCtx.stopFlag
to true to automatically trigger termination.
@Vinlic , "The most direct method is to set the video duration to be the same as the audio duration", yes, that's what i'm talking about. How to do it in pagePrepareFn ? Also if you preload audio in wvc.createSingleVideo({ ... }).addAudio({ ... });, then you probably can return audio duration.
@ivangusev
You can update to 0.0.32, and then modify this.duration
in the pagePrepareFn
function to achieve the goal:
const video = wvc.createSingleVideo({
...
pagePrepareFn() {
this.duration = 10000;
}
});
@Vinlic, i can't confirm. I updated to 0.0.32. Now i got error:
Error: Cannot set properties of undefined (setting 'duration')
Also, is it possible to access this.audios this way?
@ivangusev Have you confirmed that the "this" pointer is pointing to the correct object? Yes, this.audios can also be accessed.
@Vinlic, "this" is undefined inside pagePrepareFn
@ivangusev Can you provide the parameters of createSingleVideo? If you use arrow functions you lose the "this" pointer, which should normally point to the SingleVideo instance.
@Vinlic , you right, i use arrow function syntax for pagePrepareFn :) So all clear and i confirm it works well. Thanks a lot for your work and support!
I want to stop video recording when mp3 audio is finished (+ some gap). May be i can use video.addAudio() somehow? Another idea is to use pagePrepareFn and "onloadedmetadata" event. But how to update "duration" setting at this moment?