Skip to content

Commit

Permalink
added getPreview()
Browse files Browse the repository at this point in the history
  • Loading branch information
chuikoffru committed Nov 30, 2023
1 parent 98b4b73 commit d6cb51d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qwik-media-recorder",
"version": "1.1.0",
"version": "1.1.1",
"description": "Qwik hook for record audio from microphone",
"main": "./lib/index.qwik.mjs",
"qwik": "./lib/index.qwik.mjs",
Expand Down
20 changes: 12 additions & 8 deletions src/hooks/useMediaRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type HookReturn = {
startRecording: QRL<() => Promise<void>>;
pauseRecording: QRL<() => void>;
resumeRecording: QRL<() => void>;
getPreview: QRL<() => Blob>;
stopRecording: QRL<() => void>;
statusRecording: Signal<RecordingStatus>;
clearRecording: QRL<() => void>;
Expand Down Expand Up @@ -197,20 +198,22 @@ export const useMediaRecorder = (options?: Options): HookReturn => {
transcript.value = "";
});

/**
* Получаем предваарительное состояние записи
*/
const getPreview = $(() => {
return new Blob(chunks.value as BlobPart[], { type: "audio/ogg; codecs=opus" });
})

/**
* Остановить запись
*/
const stopRecording = $(() => {
const stopRecording = $(async () => {
if (!store.value.mediaRecorder) return;
console.log(`stopRecording`);
const nonUndefinedChunks = chunks.value.filter(chunk => chunk !== undefined) as BlobPart[];

if (nonUndefinedChunks.length === 0) {
console.error('No valid chunks to combine.');
return;
}

// Создаем уникальный url для записи
const data = new Blob(nonUndefinedChunks, { type: "audio/ogg; codecs=opus" });
const data = await getPreview();

// Создаем уникальный url для записи
const url = URL.createObjectURL(data);
Expand Down Expand Up @@ -305,6 +308,7 @@ export const useMediaRecorder = (options?: Options): HookReturn => {
pauseRecording,
stopRecording,
resumeRecording,
getPreview,
clearRecording,
statusRecording,
duration,
Expand Down

0 comments on commit d6cb51d

Please sign in to comment.