Generating a new Blob through assembling MediaRecorder blob sections leads to a blank Blob

I’ve encountered a peculiar issue with the new Blob constructor. My code returns an array of Blobs from the MediaRecorder:

https://i.sstatic.net/X8Z7c.png

However, when trying to work with this blob in my code, calling new Blob(audioChunks) results in an empty array being outputted. Strangely, running the same command directly in the console generates a new Blob correctly! Here's the complete method:

navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
        const mediaRecorder = new MediaRecorder(stream);
        mediaRecorder.start();

        const audioChunks = [];
        mediaRecorder.addEventListener("dataavailable", event => {
          audioChunks.push(event.data);
        });

        sleep(1000).then(r => {
          mediaRecorder.stop();
          console.log(audioChunks) // Show the audioChunks
          console.log(new Blob(audioChunks)) // Display the failed blob
          let audio = new File(new Blob(audioChunks), `${name}.webm`, {
            type: "audio/webm;codecs=opus"
          });
          global.addTrack("filename", audio, id);
          console.log(audioChunks)
        });
      });

Upon clicking the button that triggers this process, I receive the following console output:

https://i.sstatic.net/oylWj.png

This functionality is constructed as a method in Vue.js, but it’s uncertain whether that plays a role in the issue or not.

Answer №1

It seems like one issue you might be facing is that the timeslice is not being set in mediaRecorder.start(), causing the sleep timeout to trigger before any data is received. This can be a problem especially for short tests.

To adjust the timeslice to a smaller value (e.g. 100ms):

mediaRecorder.start(100);

While there may be other challenges ahead, this should address your initial query.

On a side note, you can directly pass an array of blobs to new File() instead of a blob of blobs. I encountered an issue with this and resolved it by modifying the code as follows:

let audio = new File(audioChunks, `${name}.webm`, {
    type: "audio/webm;codecs=opus"
});

I'm unsure about the purpose of the line:

global.addTrack("filename", audio, id);

An error message stating 'Uncaught ReferenceError: global is not defined' occurs when I encounter this line. Can you provide clarity on its function?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

utilizing javascript once form elements are dynamically inserted

While dynamically constructing form elements, I encountered an issue with generating unique IDs when the form is submitted. Everything works fine except for the JavaScript function responsible for populating the year in a dropdown selection. The issue ari ...

Two separate entities link to a shared occurrence

Two namespaces are at play here: '/' and /notification If I trigger an event in the '/' namespace, how can I listen to the same event in the '/notification' namespace? It would be helpful if someone could provide an explanati ...

When refreshed, CSS and JavaScript were not loaded

As a newcomer to AngularJs, I am facing an issue that has left me puzzled. I am attempting to create a single-page application using AngularJS + ExpressJS. Everything is functioning properly, but I am encountering a problem upon page refresh. For example, ...

Cookie Multitree: An Innovative JsTree Solution

Hello everyone, I am currently using jstree and have come across a couple of issues with having multiple trees on the same page. Here are my two problems: 1) I am looking to implement cookies to keep track of which nodes are open in each tree. I attempted ...

Height of the div dynamically increases upwards

Just a quick question - is there a way to make position: fixed divs at the bottom of an element (such as the body) grow upwards as content is dynamically added? Maybe something like anchor: bottom or increase: up? I'm thinking that using JavaScript m ...

Generate a new style element, establish various classes, and append a class to the element

Is there a more efficient solution available? $("<style>") .attr("type", "text/css") .prependTo("head") .append(".bor {border:2px dotted red} .gto {padding:10px; font-size:medium}"); $("input:text").addClass("bor gto").val("Enter your t ...

Using AngularJS and JavaScript, set the Submit button to be enabled only when the email input is valid and a value is selected in

I'm trying to create a form that includes an email input field and a drop-down list sourced from a database array. Initially, the submit button is disabled when the form loads. My goal is to figure out how to activate the submit button only when the ...

Retrieving information and employing the state hook

Currently, my goal is to retrieve information from an API and utilize that data as state using the useState hook. fetch('https://blockchain.info/ticker') // Execute the fetch function by providing the API URL .then((resp) => resp.json()) // ...

Issue: (SystemJS) Unable to find solutions for all parameters in $WebSocket: ([object Object], [object Object], ?)

Upon running the code snippet below, an error is thrown: Error: (SystemJS) Can't resolve all parameters for $WebSocket: ([object Object], [object Object], ?). app.component.ts import { Component } from '@angular/core'; import {$WebSocket} ...

In the event of any unexpected errors while utilizing an API, a ticket will be automatically generated on Jira through the use of Vue.js

After successfully hitting the API through Postman and creating a ticket on Jira, I encountered a CORS error when attempting to do the same using an index.js file in VueJS. The flow is unclear to me as generating a demo error results in nothing being sho ...

Struggling to delete event listeners in TypeScript using object-oriented programming with JavaScript

After researching the issue, I have discovered that the onMouseUp event is being fired but it is not removing the EventListeners. Many individuals facing a similar problem fail to remove the same function they added initially. Upon reading information fr ...

Ways to showcase an array with HTML content in AngularJS without using ng-repeat

Can someone help with this coding issue? "elements" : ["<p>Element 1</p>","<span>Element 2</span>"] I want to achieve the following output: <div id="wrapper"> <p>Element 1</p> <span>Element 2</s ...

Nested for loop in JavaScript causing the display of only the final value of the iterating object

When constructing a JSON array object using two different arrays, I noticed that the value of the last iterated value is being assigned to every element in the array. Specifically, for the serial number element, only the last iterated value is being displa ...

Is there a way to execute a Node 6 npm package within a Node 5.6.0 environment?

I am currently utilizing a tool called easy-sauce to conduct cross-browser JavaScript tests. Essentially, my package.json file references this tool for the test command: { "scripts": { "test": "easy-sauce" } } Everything runs smoothly when I exec ...

How to dynamically generate data with exceljs

Currently, I am attempting to download JSON data into an Excel spreadsheet. One of my requirements is to insert an image in cell a1 and then bold the headers. The code snippet below was sourced from Google; however, I need to populate the data dynamically ...

Steps for showing personalized validation error messages in Angular 7

Is there a way to highlight the input field of a form with a red border and display the message Password is invalid when a user types in a password that does not match the set password? I have managed to see the red border indicating an error when I enter ...

Avoiding the triggering of jQuery events from child elements

Here is the code snippet I am working with: <html> <head> <script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"> </script> </head> <body> <div id=&q ...

Utilize JavaScript to iterate through a JSON object and retrieve the indices that meet the specified criteria

While I found a previous answer that somewhat addresses my issue, I am seeking guidance on how to return an array of the indexes where a specific value appears. For example, if **18A38** is the target value, it should return the positions [1,3]. The sampl ...

Switch div and expand/shrink the rest

Apologies for what might seem like a trivial question, but after working for a few hours now, I'm finding it difficult to wrap my head around this. My initial instinct is to handle this by manipulating the entire div structure with JavaScript, but I c ...

Attempting to link the input field with a data value on a Vue page

I'm currently facing an issue with my table and binding the input element to the "project_settings" object. The goal is to have the values inside the project_settings object change based on whether the checkbox is checked or not. However, every time I ...