I gave my idea a shot but unfortunately I'm running into the issue that I cannot just discard older chunks. I'm assuming the first chunk aka the beginning contains some vital information/header, so the recording gets corrupted once the 30 second mark is passed because that first chunk gets removed. Keeping it also does not properly work and just creates some nice visual glitches in the resulting video if it works at all.
I found very little information on this and no real solutions. Not sure if there is some kind of magic one could employ to get this to work. The only possible solution I saw (although in a different context) was this stackoverflow.com/questions/42127276/trim-or-cut-audio-recorded-with-mediarecorder-js
But I have no clue how to actually implement this since it's for audio and not video.
I can't post the c3p right now but here's the relevant js code which almost works but alas.
> export class ReplaySystem {
constructor() {
this.stream = document.querySelector("canvas").captureStream();
this.highlightDuration = 10;
this.mediaRecorder = new MediaRecorder(this.stream, {"mimeType": "video/webm"});
this.mediaRecorder.ondataavailable = this.dataAvailable.bind(this);
this.replay = [];
}
startRecording() {
this.mediaRecorder.start(1000);
console.log("Recording started");
}
stopRecording() {
this.mediaRecorder.stop();
this.replay = [];
console.log("Recording stopped");
}
addChunk(chunk) {
this.replay.push(chunk);
if(this.replay.length > this.highlightDuration) {
this.replay.shift();
}
}
dataAvailable(ev) {
this.addChunk(ev.data);
}
captureHighlight(runtime) {
const highlight = new Blob(this.replay, {type: 'video/webm'});
const url = URL.createObjectURL(highlight);
runtime.callFunction("downloadHighlight", url);
}
}
Yeah, I don't know JS so I can't provide much feedback, but thanks for trying it out. I suppose if this doesn't work I can just make a system where the game records a whole level/session automatically, and you can use a button to download the recorded clip, but that isn't as cool in my opinion so I'll keep my eyes open for a solution.