Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. componentDidMount = async () => {
  2. let stream;
  3. try {
  4. stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  5. } catch (error) {
  6. this.setState({
  7. accept: false
  8. })
  9. }
  10. this.setState({ stream });
  11. }
  12.  
  13. startRecord = () => {
  14. const { stream } = this.state;
  15. const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  16. const recorder = new RecorderJS(audioContext);
  17. recorder.init(stream);
  18. this.setState(
  19. {
  20. recorder,
  21. recording: true
  22. },
  23. () => {
  24. recorder.start();
  25. }
  26. );
  27. }
  28.  
  29. stopRecord = async () => {
  30. const { recorder } = this.state;
  31. recorder.stop().then(({ blob }) => {
  32. this.uploadFile(blob);
  33. })
  34. this.setState({
  35. recording: false
  36. });
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement