Comments (9)
@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.
I don't understand how to use it in render. It's rendering the jsx inline.
from react-media-recorder.
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.
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.
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.
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.
@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.
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.
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)
- can't pass pre-commit checks
- Blob is not defined HOT 5
- MP4 file missing all meta info HOT 5
- Unable to playback the recorded video on iOS HOT 1
- How to mute on initial start of recording.
- How to use with webpack.config throw error
- Add support on audio/ogg by using "opus-media-recorder"?
- ERR_REQUEST_RANGE_NOT_SATISFIABLE while using Constraints object
- Mobile Browser Not Supported HOT 4
- Error: unmuteAudio is not a function HOT 1
- onError method
- Cross browser audio/video recording not supported on various browsers HOT 2
- why the pauseRecording function don't stop also the preview ? HOT 1
- Start play button doesn't show video on screen while recoding
- Recorder asking permission to use camera and micro many times, on IOS
- Videoframe distoring and blinking @1.6.0
- not working on ipad
- Switch camera and mic HOT 1
- previewAudioStream doesn't have any data HOT 1
- Error: There is already an encoder stored which handles exactly the same mime types HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-media-recorder.