Coder Social home page Coder Social logo

Comments (9)

DeltaCircuit avatar DeltaCircuit commented on August 26, 2024

@cameronroe You can access mediaBlob in the render function.

It's a blob url, so you may use it like:

let audio = new Audio(mediaBlob);
audio.play();  

from react-media-recorder.

ninjasort avatar ninjasort commented on August 26, 2024

I don't understand how to use it in render. It's rendering the jsx inline.

from react-media-recorder.

DeltaCircuit avatar DeltaCircuit commented on August 26, 2024

Oh, I thought you wanted an Audio object. You can render an <audio /> in the render like this:

<ReactMediaRecorder  
  audio
  render={({ status, startRecording, stopRecording, mediaBlob }) => (
    <div>
      <p>{status}</p>
      <button onClick={startRecording}>Start Recording</button>  
      <button onClick={stopRecording}>Stop Recording</button>  
      <audio src={mediaBlob} controls />  
    </div>  
  )}  
/>  

If you're still having problems, can you post your code here? I can't really guess what's happening to you without seeing the code.

from react-media-recorder.

ninjasort avatar ninjasort commented on August 26, 2024

I basically had that... but I want to record the audio and then use it elsewhere in my code:

So I had:

<ReactMediaRecorder  
  audio
  render={({ status, startRecording, stopRecording, mediaBlob }) => (
    <div>
      <p>{status}</p>
      <button onClick={startRecording}>Start Recording</button>  
      <button onClick={stopRecording}>Stop Recording</button>  
      <audio src={mediaBlob} controls />  
      {this.setState({audio: new Audio(mediaBlob))}
    </div>  
  )}  
/>  

from react-media-recorder.

DeltaCircuit avatar DeltaCircuit commented on August 26, 2024

You can't use setState() in render. This will lead to infinite recursion. You can wrap your entire recorder component with ReactMediaRecorder if that's what you want. That's the whole idea of render props.

I'm not quite sure about achieving this behavior with this design pattern.

from react-media-recorder.

DeltaCircuit avatar DeltaCircuit commented on August 26, 2024

But I see your point. How about a whenStopped prop to ReactMediaRecorder? Which will fire once the recorder stops. The function will be invoked with the blobUrl. So, you can use it to setState() like this:

<ReactMediaRecorder  
  audio
  whenStopped={blobUrl=>this.setState({ blobUrl })}
  render={({ status, startRecording, stopRecording, mediaBlob }) => (
    <div>
      <p>{status}</p>
      <button onClick={startRecording}>Start Recording</button>  
      <button onClick={stopRecording}>Stop Recording</button>  
      <audio src={mediaBlob} controls />  
    </div>  
  )}  
/>  

Sounds good? I'll be patching this shortly.

from react-media-recorder.

DeltaCircuit avatar DeltaCircuit commented on August 26, 2024

@cameronroe The patched version ( 0.7.0 ) is live in npm registry.
Do a

$> npm i react-media-recorder@latest  

and try again with whenStopped hook. Let me know / reopen this if you're still getting any issues.

Thanks!

from react-media-recorder.

AmeerHamzaRiaz avatar AmeerHamzaRiaz commented on August 26, 2024

Hi, I also can't figure out how to send this audio converted from blobUrl to s3.
Also, When I do
let audio = new Audio(mediaBlob);
audio.play(); // this works
audio.duration //but this returns NaN

Thanks

from react-media-recorder.

dasler-fw avatar dasler-fw commented on August 26, 2024

Thats how you can get blob from mediaBlobUrl or change mediaBlobUrl to blob (for searchers):

const handleSave = async () => {
    const audioBlob = await fetch(mediaBlobUrl).then((r) => r.blob());
    const audioFile = new File([audioBlob], 'voice.wav', { type: 'audio/wav' });
    const formData = new FormData(); // preparing to send to the server

    formData.append('file', audioFile);  // preparing to send to the server

    onSaveAudio(formData); // sending to the server
  };

from react-media-recorder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.