Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
legokichi committed Feb 20, 2024
1 parent 2513482 commit 5d0378e
Showing 1 changed file with 12 additions and 51 deletions.
63 changes: 12 additions & 51 deletions test/example_seekable.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
await main_from_recorder(duration, codec);
} else {
const file = params.has("file")
? (params.get("file") as string)
? params.get("file")
: "./chrome57.webm";
await main_from_file(file);
}
}

async function main_from_file(file: string) {
async function main_from_file(file) {
const decoder = new Decoder();
const reader = new Reader();
reader.logging = true;
Expand Down Expand Up @@ -74,19 +74,19 @@
refinedReader.stop();
}

async function main_from_recorder(duration: number, codec: string) {
async function main_from_recorder(duration, codec) {
const decoder = new Decoder();
const reader = new Reader();
reader.logging = true;
reader.logGroup = "Raw WebM Stream (not seekable)";

let tasks: Promise<void> = Promise.resolve(void 0);
let tasks = Promise.resolve(void 0);
let webM = new Blob([], { type: "video/webm" });

const devices = await navigator.mediaDevices.enumerateDevices();
console.table(devices);

const stream: MediaStream = await navigator.mediaDevices.getUserMedia({
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
});
Expand All @@ -95,7 +95,7 @@
mimeType: `video/webm; codecs="${codec}, opus"`
});

const ondataavailable = (ev: BlobEvent) => {
const ondataavailable = (ev) => {
const chunk = ev.data;
webM = new Blob([webM, chunk], { type: chunk.type });
const task = async () => {
Expand Down Expand Up @@ -128,7 +128,7 @@
count++;
}

rec.removeEventListener("dataavailable", ondataavailable as any);
rec.removeEventListener("dataavailable", ondataavailable);
rec.stream.getTracks().map((track) => {
track.stop();
});
Expand Down Expand Up @@ -190,35 +190,35 @@
}
}

function put(elm: HTMLElement, title: string): void {
function put(elm, title){
const h1 = document.createElement("h1");
h1.appendChild(document.createTextNode(title));
document.body.appendChild(h1);
document.body.appendChild(elm);
}

function readAsArrayBuffer(blob: Blob): Promise<ArrayBuffer> {
function readAsArrayBuffer(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onloadend = () => {
resolve(<ArrayBuffer>reader.result);
resolve(reader.result);
};
reader.onerror = (ev) => {
reject(ev);
};
});
}

function sleep(ms: number): Promise<any> {
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

const saveData = (function () {
const a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("style", "display: none");
return function saveData(blob: Blob, fileName: string) {
return function saveData(blob, fileName) {
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
Expand All @@ -227,44 +227,5 @@
};
})();

// MediaRecorder API
interface BlobEvent extends Event {
data: Blob;
}

interface MediaRecorderEventMap {
dataavailable: BlobEvent;
pause: Event;
resume: Event;
start: Event;
stop: Event;
error: Event;
}

declare class MediaRecorder extends EventTarget {
constructor(stream: MediaStream, opt: any);
start(timeslice?: number): void;
stop(): void;
mimeType: string;
state: "inactive" | "recording" | "paused";
stream: MediaStream;
videoBitsPerSecond: number;
audioBitsPerSecond: number;
ondataavailable?: (ev: BlobEvent) => void;
onerror?: (ev: ErrorEvent) => void;
addEventListener<K extends keyof MediaRecorderEventMap>(
type: K,
listener: (this: MediaStream, ev: MediaRecorderEventMap[K]) => any,
useCapture?: boolean
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
useCapture?: boolean
): void;
requestData(): Blob;
}

main();

</script>

0 comments on commit 5d0378e

Please sign in to comment.